effector-react
Advanced tools
Changelog
effector-react 22.1.0
useUnit
method to read multiple stores and bind events or effects to scope in a single batched call (PR #733, #738)import {value createEvent, value createStore, value fork} from 'effector'
import {value useUnit, value Provider} from 'effector-react/scope'
const inc = createEvent()
const $count = createStore(0)
const $title = createStore('useStore example')
$count.on(inc, x => x + 1)
const App = () => {
const [count, title, incFn] = useUnit([$count, $title, inc])
return (
<>
<h1>{title}</h1>
<p>Count: {count}</p>
<button onClick={() => incFn()}>increment</button>
</>
)
}
const scope = fork()
render(
() => (
<Provider value={scope}>
<App />
</Provider>
),
document.getElementById('root'),
)
placeholder
option to useList
to render in cases of empty listconst ChatList = () => (
<div>
{useList($chats, {
fn: chat => <div>Chat {chat.name}</div>,
keys: [],
placeholder: <div>You have no chats yet. Add first one?</div>,
})}
</div>
)
defaultValue
option to useStoreMap
to return in cases when fn
returns undefinedconst ChatName = ({id}) => {
const chat = useStoreMap({
store: $chats,
keys: [id],
fn: chats => chats.find(chat => chat.id === id),
defaultValue: {id: 'default', name: 'Default chat'},
})
return <span>{chat.name}</span>
}
Gate.status
store being serialized (PR #683)Changelog
effector 22.0.0
attach({source, async effect(source, params) {}})
const scope = fork()
Unit not found in scope
error is no longer exists, any unit could be used in any scopefork
and serialize
a hundredfoldfork({values: [[$user, 'alice'], [$age, 22]]})
serialize: 'ignore'
option to createStore
to declare store as ignored by serialize
callsonlyChanges: true
a default serialize
optioncombine
arguments and throw an error in case of undefined
and non-store units (issue #509)createStoreObject
alias for combine
effector/fork
module.thru
store.map
.on
in derived stores created by store.map
and combine
event.map
, event.filterMap
and event.filter
fx.done
, fx.doneData
and other events belongs to effectsɔ
(latin small letter open o) symbol to prevent incorrect unicode parsingscope.find
which is a wrong abstraction for a new forkScope
a unit:
Scope
to is.unit
is.scope
methodscopeBind(unit, {scope})
, which is also can be used outside from .watch