redux-actionscan be found via the globals
window.ReduxActions. Okay enough setup lets start to make something with
handleAction. We can provide it our
incrementaction to let it know which action to handle, a method to handle our state transformation, and the default state.
handleActionproduced a reducer for our
reduxstore. Now that we have a reducer we can create a store.
store, we can rewrite our
rendermethod to use it instead of the
defaultState. We also want to
renderto any changes the
storemight have for us.
dispatchan action. Lets create an event listener for our increment button that will dispatch our
incrementaction creator when clicked.
handleActionlike we did for
increment, we can replace it with our other tool
handleActionswhich will let us handle both
decrementaction we can see both
decrementbuttons now function appropriately.
redux-actionshas other tools we have not yet taken advantage of. So lets investigate how we can change the code to use the remaining tools and make the code less verbose.
decrementaction creators. We can modify these lines from using
'INCREMENT_FIVE'? We would want to be able to create variations of our existing actions easily. We can abstract our logic in the reducer to our actions, making new permutations of existing actions easy to create.
reducersare looking identical. If only we could combine them somehow. Well we can!
combineActionscan be used to reduce multiple distinct actions with the same reducer.
redux-actionshas to offer. Concluding our vanilla tutorial. This doesn't mean you don't have more to learn though. Much more can be accomplished using these tools in many ways, just head on over to the API Reference to begin exploring what else
redux-actionscan do for you.