0

Here is the action itself:

import actionFromAnotherReducer from '../subfolder/reducer'

export const asyncAction = createAsyncThunk(
  'reducerName/actionName',
  async(
    data,
    { dispatch, getState }
  ) => {
    return somePromise.then(response => {
      dispatch(actionFromAnotherReducer(response))
    })
  }
)

And here is where I get this error Cannot read properties of undefined (reading 'getState'): The above error occurred in the <Provider> component. The thing is when I remove the dispatch(action), everything works, and also if I dispatch an action from the same folder reducer, it works as well. How to fix it?

Alopwer
  • 611
  • 8
  • 22
  • Which what exact code are you dispatching this thunk? – phry Jun 14 '22 at 09:42
  • @phry, I dispatch another action created with createAsyncThunk – Alopwer Jun 14 '22 at 09:49
  • I already asked very explicitly: With what exact code? Your thunk is totally fine, the chance that you are dispatching it wrong is very high. – phry Jun 14 '22 at 10:02
  • @phry, `dispatch(asyncAction({ title: 'test title' }))` – Alopwer Jun 14 '22 at 10:06
  • So that's not your problem. Then I would assume you have created some kind of circular import. Do you create your store in a separate file or in the same file as in the `Provider`? Can you move it into it's own file? Does your thunk file import something from that same file where your store is currently in or from a file that imports from there? – phry Jun 14 '22 at 10:11

0 Answers0