D
D
Daniel Chistyakov2022-01-25 23:51:57
React
Daniel Chistyakov, 2022-01-25 23:51:57

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);


Events:
export const setId = createEvent<number>();
export const setType = createEvent<number>();


Effect:
const getPosts = createEffect<IGetPostsPayload, IPosts[], Error>('get posts').use(() => getPosts({
  id: $id.stateRef.current,
  type: $type.stateRef.current,
}))


Forward:
forward({
  from: [$id, $type],
  to: getUrls,
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SANTA2112, 2022-01-26
@danielchistyakov


https: //codesandbox.io/s/unruffled-mestorf-dvbsh ?f ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question