Error: Actions must be plain objects. Use custom middleware for async actions. Using vitejs and redux-mock-store

24 views Asked by At

Actions must be plain objects. Use custom middleware for async actions. ❯ dispatch node_modules/redux-mock-store/lib/index.js:41:19

    useEffect(() => {
      dispatch(fetch({ url }))
        ^
    }, [url, reload])

Using vitejs and redux-mock-store it should mock redux dispatch function

1

There are 1 answers

0
Jair Nunes On

I forgot add middleware with redux-thunk.
import thunk from 'redux-thunk'
//...
const middlewares = [thunk]
const mockStore = configureStore(middlewares);
//...
ref: https://github.com/reduxjs/redux-mock-store#asynchronous-actions