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
{{ message }}
Repository navigation
One More Time, Error: Actions must be plain objects. Use custom middleware for async actions #546
So basically the error is coming from that line of code which actually makes sense. In order to keep the peeps from abusing it (dispatch -> return a promise or observable). However, I instead of writing the pure function that returns an object, am using a class and dispatching a new instance. to gain more strongly typed actions + satisfy my laziness .
my solution now is as so :
//OPTION 1 : global
const plainObjectMiddleWare = _ => next => action => {
next({ ...action });
};
//OPTION 2 : manual
store.dispatch({... new MyAction(1)})
//in both cases the class would be
export const MY_ACTION = 'MY_ACTION'; //compatibilitywith previous code
export class MyAction{
readonly type = MY_ACTION
constructor (readonly number){}
}
Now of course the question is why am asking here instead of of the reduxjs repo itself... well, because it is reduxJAVASCRIPT and it will be pain in the ass to explain them about Typescript and i believe since you here are doing well with Rx & TS you would get my point.
so perhaps you can add the plainObjectMiddleWare, or a decorator/transformer.
or you advice to keep it as is?
Activity