withFxActions is a React high-order component factory that injects a unique fxActions prop into the given component.
The given fxActions is a unique FxActionCreators instance representing the side-effect passed to the factory.
The consumer has complete control over when the actions are dispatched, so is responsible for calling the effect, rendering the FxState, and cleaning up with destroy().
This makes it possible to access the fxActions in the ownProps parameter passed to mapStateToProps and mapDispatchToProps.
The following example defines a connected component with the fxActions prop injected.
The mapStateToProps function uses the given fxActions to access a unique FxState for the component.
The mapDispatchToProps function wraps the call and destroy action creators with dispatch and passes them down to the underlying component.
withFxActions is a React high-order component factory that injects a unique
fxActionsprop into the given component. The givenfxActionsis a uniqueFxActionCreatorsinstance representing the side-effect passed to the factory. The consumer has complete control over when the actions are dispatched, so is responsible for calling the effect, rendering the FxState, and cleaning up withdestroy(). This makes it possible to access thefxActionsin theownPropsparameter passed tomapStateToPropsandmapDispatchToProps.The following example defines a connected component with the
fxActionsprop injected. ThemapStateToPropsfunction uses the givenfxActionsto access a unique FxState for the component. ThemapDispatchToPropsfunction wraps thecallanddestroyaction creators withdispatchand passes them down to the underlying component.// typeof Component: React.ComponentType<{ state: FxState, call: (...params) => void, destroy: () => void }> const mapStateToProps = (state, { fxActions }) => ({ state: fxActions.selector(state) }) const mapDispatchToProps = (dispatch, { fxActions }) => ({ call: (...params) => dispatch(fxActions.call(...params)), destroy: () => dispatch(fxActions.destroy()) }) const Connected = connect(mapStateToProps, mapDispatchToProps)(Component) // typeof effect: (p1: number, p2: string) => Promise<string> const WithFxActions = withFxActions(effect)(Connected)