restore

restore(event, defaultState)

Creates a Store from Event. It works like a shortcut for createStore(defaultState).on(event, (_, payload) => payload)

Arguments

  1. event Event
  2. defaultState (Payload)

Returns

Store: New store

Example

import {createEvent, restore} from 'effector'
const event = createEvent()
const store = restore(event, 'default')
store.watch(state => console.log('state: ', state))
// state: default
event('foo')
// state: foo

Try it

restore(effect, defaultState)

Creates a Store from sucessful results of Effect. It works like a shortcut for createStore(defaultState).on(effect.done, (_, {result}) => result)

Arguments

  1. effect Effect
  2. defaultState (Done)

Returns

Store: New store

Example

import {createEffect, restore} from 'effector'
const effect = createEffect({
handler: () => 'foo',
})
const store = restore(effect, 'default')
store.watch(state => console.log('state: ', state))
// state: default
effect()
// state: foo

Try it

restore(obj)

Creates an object with stores from object with values

Arguments

  1. obj (State)

Returns

Store: New store

Example

import {restore} from 'effector'
const {foo, bar} = restore({
foo: 'foo',
bar: 0,
})
foo.watch(foo => {
console.log('foo', foo)
})
// => foo 'foo'
bar.watch(bar => {
console.log('bar', bar)
})
// => bar 0

Try it