You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disclaimer: I'm aware that this is not backward compatible.
Current behaviour
Right now, an action callback receives the thunk params last (source):
result=fn(...args,{getState, dispatch, extra});
Problem
It's harder to use optional params or just to validate them.
constmyAction=createActionThunk('MY_ACTION',(a,b,{ getState })=>{// do something with getStateif(!b){// do something or reject}returnfetchData(a,b);});
Then, calling myAction(a) will fail either because of the { getState } param destructuring, or because b is always present (as the thunk params object).
Proposition
Just place the thunk params object first, then spread the args.
result=fn({getState, dispatch, extra}, ...args);
Then, our action with optional params and/or validation will always work.
constmyAction=createActionThunk('MY_ACTION',({ getState },a,b)=>{// do something with getStateif(!b){// do something or reject}returnfetchData(a,b);});
The text was updated successfully, but these errors were encountered:
Disclaimer: I'm aware that this is not backward compatible.
Current behaviour
Right now, an action callback receives the thunk params last (source):
Problem
It's harder to use optional params or just to validate them.
Then, calling
myAction(a)
will fail either because of the{ getState }
param destructuring, or becauseb
is always present (as the thunk params object).Proposition
Just place the thunk params object first, then spread the
args
.Then, our action with optional params and/or validation will always work.
The text was updated successfully, but these errors were encountered: