Tarjima qoshish uchun havola boyicha o'tib Pull Request oching (havolaga o'tish).
Standart til uchun tarkibni ko'rsatadi.
Troubleshooting Effector
Common Errors
store: undefined is used to skip updates. To allow undefined as a value provide explicit {Ā skipVoid:Ā falseĀ } option
This error indicates that you are trying to pass undefined
as a value to your store, which might not be the intended behavior.
If you really need to store undefined
, pass an object with {Ā skipVoid:Ā falseĀ }
as the second argument to createStore
:
const $store = createStore(0, { skipVoid: false,});
no handler used in [effect name]
This error occurs when calling an effect without a handler. Make sure you passed a handler to the createEffect
method during creation, or later when using the .use(handler)
method.
serialize: One or more stores dont have sids, their values are omitted
Before version 23.3.0, this error was also known as: There is a store without sid in this scope, its value is omitted
.
This error commonly occurs in SSR scenarios due to the absence of an sid
(stable id), which is required for proper hydration of store data from the server to the client.
To fix this, add an sid
to your store. You can do this in one of the following ways:
-
Manually specify an
sid
by providing an object with asid
property as the second argument tocreateStore
:const $store = createStore(0, {sid: "unique id",});
For more details, see Understanding sid
and its purpose.
scopeBind: scope not found
This error occurs when a scope is lost at some point in execution, preventing scopeBind
from associating an event or effect with the correct execution scope.
It may be caused by:
- Using a āscope-freeā mode where scopes are not present in your application.
- Calling units outside of a scope.
Possible Solutions:
-
Ensure
scopeBind
is used within effects:const event = createEvent();// ā - Do not call scopeBind inside callbacksconst effectFx = createEffect(() => {setTimeout(() => {scopeBind(event)();}, 1111);});// ā - Use scopeBind inside the effectconst effectFx = createEffect(() => {const scopeEvent = scopeBind(event);setTimeout(() => {scopeEvent();}, 1111);}); -
Ensure that your units are used inside a scope:
- When working with a framework, use
useUnit
. - If calling an event or effect outside a framework, use
allSettled
and provide the appropriatescope
as an argument.
- When working with a framework, use
If necessary, and you want to suppress the error, you can pass {Ā safe:Ā trueĀ }
as an option:
const scopeEvent = scopeBind(event, { safe: true,});
call of derived event is not supported, use createEvent instead
This error occurs when you try to call a derived event as a function. Derived events are created by methods like .map()
, .filter()
, .filterMap()
, as well as the sample
operator.
To fix this, use an event created via createEvent
.
unit call from pure function is not supported, use operators like sample instead
This error occurs when you try to call events or effects from pure functions in Effector:
-
Calling events in event methods
When you try to call one event inside another eventās.map()
,.filter()
,.filterMap()
, or.prepend()
methods. -
Calling events in store handlers
When attempting to call an event in a.on()
handler, inside the.map()
method, or in theupdateFilter()
configuration property of a store. -
Calling events in
sample
functions
When calling an event in thefn
orfilter
function of thesample
operator.
How to fix: Instead of calling events in pure functions, use declarative operators, for example, sample
.
Gotchas
sample.fn
does not narrow the type passed from sample.filter
A common type-related issue with sample
occurs when a check is performed in filter
, but fn
does not receive the correctly narrowed type. To resolve this, you can add type predicates or use the effector-action
library, which helps simplify conditional types:
import { sample } from "effector";
const messageSent = createEvent<Message>();const userText = createEvent<string>();
sample({ clock: messageSent, filter: (msg: Message): msg is UserMessage => msg.kind === "user", fn: (msg) => msg.text, target: userText,});
import { createAction } from "effector-action";
const userText = createEvent<string>();
const messageSent = createAction({ target: userText, fn: (userText, msg: Message) => { if (msg.kind === "user") { userText(msg.txt); } },});
My state did not change
If your state does not update as expected, you are likely working with scopes and, at some point, the active scope was lost. As a result, your unit executed in the global scope instead.
Typical places where this happens:
setTimeout
/setInterval
addEventListener
WebSocket
- direct promise calls inside effects
- third-party libraries with async APIs or callbacks.
Solution:
Bind your event or effect to the current scope using scopeBind
:
// ā
correct way
const event = createEvent();
const effectFx = createEffect(() => { const scopedEvent = scopeBind(event);
setTimeout(() => { scopedEvent(); }, 1000);});
// ā event will execute in the global scope
const event = createEvent();
const effectFx = createEffect(() => { setTimeout(() => { event(); }, 1000);});
Using units without useUnit
If youāre using events or effects in a framework without useUnit
, this may also lead to scope loss.
To fix this, pass the unit to the useUnit
hook and use the returned value:
// ā
hook used
import { event } from "./model.js";import { useUnit } from "effector-react";
const Component = () => { const onEvent = useUnit(event);
return <button onClick={() => onEvent()}>click me</button>;};
// ā direct unit call
import { event } from "./model.js";
const Component = () => { return <button onClick={() => event()}>click me</button>;};
Using useUnit
is the recommended approach for working with units.
No Answer to Your Question?
If you couldnāt find the answer to your question, you can always ask the community:
Ingliz tilidagi hujjatlar eng dolzarb hisoblanadi, chunki u effector guruhi tomonidan yozilgan va yangilanadi. Hujjatlarni boshqa tillarga tarjima qilish jamiyat tomonidan kuch va istaklar mavjud bo'lganda amalga oshiriladi.
Esda tutingki, tarjima qilingan maqolalar yangilanmasligi mumkin, shuning uchun eng aniq va dolzarb ma'lumot uchun hujjatlarning asl inglizcha versiyasidan foydalanishni tavsiya etamiz.