Search code examples
reactjsreduxreact-reduxuse-effectdispatch

Error: Actions must be plain objects. Instead, the actual type was: 'Promise'. You may need to add middleware


I'm trying to get the list of user and clients using dipatch and I get this error: "Error: Actions must be plain objects. Instead, the actual type was: 'Promise'. You may need to add middleware to your store setup to handle dispatching other values, such as 'redux-thunk' to handle dispatching functions."

Here is the code where I get the error:

useEffect(() => {
        dispatch(ListClients());
        dispatch(ListUsers());
    }, [dispatch]);

Solution

  • What is the definition of ListClients() and ListUsers ?

    I'm pretty sure your code should look like this:

    useEffect(() => {
        dispatch(ListClients);
        dispatch(ListUsers);
    }, [dispatch]);
    

    Or your functions do not have the right signature.