mardi 26 novembre 2019

React Redux sync action return error when giving plain object

I'm learning React/Redux. I have an action file:

import { RESIZE } from './actionType';

export const setSize = msg => (dispatch) => { 
    dispatch({ type: RESIZE, size: msg }); 
};

If I use above action, it will fail updating the redux store. But if I do it like below, redux store will be updated successfully:

import { RESIZE } from './actionType';

export const setSize = msg => ({ type: RESIZE, size: msg }); 

In the first example, console keeps giving an error which is 'action must be a plain object. Use custom middleware for async actions'. I am using a plain object in action. Then what's the problem with my code. I have search similar posts but nothing is applicable to my problem.




Aucun commentaire:

Enregistrer un commentaire