createStore(defaultState, config?)

Creates a store.

Arguments

  1. defaultState (State): Default state
  2. config (Object): Optional configuration
    • name (String): Name for the store. Babel plugin can set it from 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 store
const selectedTodos = todos.map(todos => {
return todos.filter(todo => !!todo.selected)
})
// Handle side effects
todos.watch(state => {
console.log(state)
})

Try it