0

I am getting following error on redux store for async calls, I read few of the stack-overflow solutions but it doesn't help much :

Error:

Uncaught Error: Actions must be plain objects. Use custom middleware for async actions.
    at dispatch (createStore.js:105)
    at Object.getDeviceRedistributeIsisToBGPStatus (bindActionCreators.js:14)

Sharing the function being called from component file:

> export const getDeviceRedistributeIsisToBGPStatus =  (primaryDevice,
    > peerDevice) => {   return async dispatch => {
    >     const primaryConst = (primaryDevice !== '') ? await getRedistributeIsisToBGPStatus(primaryDevice) : false
    >     const peerConst = (peerDevice !== '') ? await getRedistributeIsisToBGPStatus(peerDevice): false
    >     const res = (primaryConst !== false || peerConst !== false ) ? false: true
    >     if(res){
    >       dispatch({ type: actionTypes.UPDATE_FORM_FIELD_VALUE, name:'redistributeIsisToBgp',value:false});
    >     }
    >     dispatch({
    >       type: actionTypes.DISABLE_REDISTRIBUTE_ISIS_TO_BGP_CHECKBOX, redistributeIsisToBGPStatus: res
    >     })   } }

Can somebody please let me know where I am going wrong.

  • Is your store configured to use the thunk middleware? If you're using redux-toolkit, it is used by default, if not you have to do it manually. – timotgl Jul 13 '22 at 09:49
  • I am using redux-utils for creating store ... using createContext – Srishti Tiwari Jul 13 '22 at 09:52
  • The github project behind https://www.npmjs.com/package/redux-utils does not exist anymore and the last update to the npm package was 6 years ago. If you have the option, I'd advise to migrate to redux-toolkit. But reading the npm package description, it still looks like you have to manually and explicitly use the thunk middleware when configuring your store. As in, `redux-thunk` needs to be imported and used somewhere. – timotgl Jul 13 '22 at 10:01
  • can you share some sample code on how to use redux-thunk – Srishti Tiwari Jul 13 '22 at 10:17
  • The npm package I linked shows an example with `applyMiddleware`. – timotgl Jul 13 '22 at 10:38

0 Answers0