Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { createStore } from 'redux'
- /**
- * This is a reducer, a pure function with (state, action) => state signature.
- * It describes how an action transforms the state into the next state.
- *
- */
- function counter(state = 0, action) {
- switch (action.type) {
- case 'INCREMENT':
- return state + 1
- case 'DECREMENT':
- return state - 1
- default:
- return state
- }
- }
- // Create the store
- let store = createStore(counter);
- /**
- * Actions
- *
- */
- store.dispatch({ type: 'INCREMENT' })
- // 1
- store.dispatch({ type: 'INCREMENT' })
- // 2
- store.dispatch({ type: 'DECREMENT' })
- // 1
Add Comment
Please, Sign In to add comment