createStore(defaultState, config?)
Creates a store.
Arguments
defaultState
(State): Default stateconfig
(Object): Optional configurationname
(String): Name for the store. Babel plugin can set it from the variable name, if not passed explicitly in config.
Returns
Store: New store
Example
import {createEvent, createStore} from 'effector'
const addTodo = createEvent()const clearTodos = createEvent()
const todos = createStore([])todos // Add reducer .on(addTodo, (state, todo) => [...state, todo]) // Will reset store to default state when clearTodos is fired .reset(clearTodos)
// Create derived storeconst selectedTodos = todos.map(todos => { return todos.filter(todo => !!todo.selected)})// Handle side effectstodos.watch(state => { console.log(state)})