Answer the question
In order to leave comments, you need to log in
How to call an effect with 2 or more dependencies from an Effector store?
Recently I started to master Effector and there is a need to fetch the date when one of two or more dependencies changes. As I understand it, at the moment the parameters are passed to the getPosts function with a crutch. I would like to hear best practices without using useEffect on the front.
Stores:
export const $id = createStore<number>(0)
.on(setId, (_, id: number) => id);
export const $type = createStore<number>(1)
.on(setType (_, type: number) => type);
export const setId = createEvent<number>();
export const setType = createEvent<number>();
const getPosts = createEffect<IGetPostsPayload, IPosts[], Error>('get posts').use(() => getPosts({
id: $id.stateRef.current,
type: $type.stateRef.current,
}))
forward({
from: [$id, $type],
to: getUrls,
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question