A simple implementation of Flux that is loosely based on Redux.
You can pass actions directly or return a function that will dispatch actions asynchronously.
When using a function you get
getState functions as arguments.
Reducers work similar to Redux but utilise Immutable.js by default.
;;// createState is a convenience wrapper for Immutable.fromJS();;
You can also pass an optional
sideEffect function as the third argument to
createReducer that will be called (passing the updated state) once all reducer functions are called.
And then you might combine your reducers:
This will create a tree structure with each reducer managing the state under the same key in the store.
In this example, the store would look something like:
You can also pass a
sideEffect function as the second argument to
combineReducers. This function will be called with the updated state once all reducers are run.
You can then use this new reducer as context state in a
First, create a store:
Then create a
Provider at the top level of your app to provide state.
For example, in your
And now you have a choice of how you want to consume the context - hooks or HOCs.
You can use
useDispatch to hook into the state and actions of the provider.
You can use
connect to create a HOC that maps state and dispatch calls into the wrapped component.
- Nathan Hoad - firstname.lastname@example.org