How to get effect's parameters in pending method Effector?

92 views Asked by At

I have something like this :

const getUsersEffect = createEffect(async (payload) => {
  return [{id: 1, name: "John Doe"}];
});

const usersStore = createStore({
    users: []
});

usersStore.on(getUsersEffect.pending, (state, isPending) => {
  // I want to get {MY_CUSTOM_KEY: 10} here
});

getUsersEffect({MY_CUSTOM_KEY: 10});

I want to get the passed parameters ({MY_CUSTOM_KEY: 10}) in the pending effect, how to achieve it? No information about it in documentation

1

There are 1 answers

0
John On

const getUsersEffect = createEffect(async (payload) => {
  return [{id: 1, name: "John Doe"}];
});

const usersStore = createStore({
    users: []
});

usersStore.on(getUsersEffect, (state, payload) => {
  console.log(payload["MY_CUSTOM_KEY"]); // 10
});

getUsersEffect({MY_CUSTOM_KEY: 10});