Answers for "redux get state without store"

1

redux get state without store

/*
* MyStore module
*/

import { createStore } from 'redux'

// action creator
export const setFoo = value => ({type: FOO, value: value})

// init state
const initState = {
	foo: 'foo'
}

// reducer
const reducer = (state = initState, action) => {
  case FOO:
	return { ...state, foo: action.value}
  default:
	return state
}

// create store
export const store = createStore(reducer)


/*
* MyScreen client
*/
import { setFoo, store } from './MyStore'

// selector
const foo = store.getState().foo

// dispatch
store.dispatch(setFoo('bar')
Posted by: Guest on December-30-2020

Code answers related to "redux get state without store"

Code answers related to "Javascript"

Browse Popular Code Answers by Language