Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { createStore } from 'redux'
- function reducer(state = { count: 0 }, action) {
- switch (action.type) {
- case 'increment':
- return { ...state, count: state.count + 1 }
- default:
- return state
- }
- }
- const store = createStore(reducer, undefined)
- console.log('init', store.getState())
- store.dispatch({ type: 'increment' })
- console.log('dispatched', store.getState())
- const snapshot = store.getState()
- const newStore = createStore(reducer, snapshot)
- console.log('take over', newStore.getState())
- newStore.dispatch({ type: 'increment' })
- console.log('dispatched', newStore.getState())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement