Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Redux-Leaves: basic example

node v10.24.1
version: 2.0.0
endpointsharetweet
// Imports for Redux and Redux-Leaves // (Sandbox note: Runkit does not support import) const { createStore } = require('redux') const reduxLeaves = require('redux-leaves').default // Your job: provide some initial state const initialState = { counterOne: 0, counterTwo: 0 } // Redux-Leaves's job: to write your reducer and actions for you const [reducer, actions] = reduxLeaves(initialState) // Create your Redux store using the given reducer const store = createStore(reducer) store.getState()
// Let's create an action to increment counterOne by 3 const actionToIncrementCounterOneByThree = actions.counterOne.create.increment(3) // Dispatch our created action to the store store.dispatch(actionToIncrementCounterOneByThree) // The store's state will be updated! store.getState() // { counterOne: 3, counterTwo: 0 }
// Now let's increment counterTwo by 10 store.dispatch(actions.counterTwo.create.increment(10)) store.getState() // { counterOne: 3, counterTwo: 10 }
Loading…

no comments

    sign in to comment