Nami
Nami

Reputation: 155

unhandled rejection: action is undefined React js and Redux

I am new to Redux and I have encountered this issue and cannot seem to find a solution for it.

I have several API calls inside of thunks and they all work fine. This one however fails. It is different to the others in the sense that I am implementing a search feature that uses payload. I have tried to debug it but can't seem to find where the error happens exactly.

this is the error that I get on the screen: enter image description here

these are the action, reducer and code in the search component:action thunks redux code

and this is the logic to connect the component to the store and access state and actions:

connection to store

Surely it must be something I am not fully understanding, I hope you can make some sense out of this.

Upvotes: 0

Views: 334

Answers (1)

rotimi-best
rotimi-best

Reputation: 1922

You should change action.loadSearchResults.result to action.searchResults.result. I am assuming there is a key called result you are getting in your response from HomePageApi.searchResults(searchInput).

I know this because in your action you have this code:

export function searchMoviewResultsSuccess(searchResults) {
  return {
    type: types.SEARCH_RESULTS_SUCCESS,
    searchResults: searchResults // This is the key you should get in your reducer not `loadSearchResults`
  }
}

Upvotes: 2

Related Questions