Search code examples
javascriptreactjsreact-hookstypeerror

TypeError: Cannot read properties of undefined (reading 'map') in react dev


in this the code is working normally when the api call is not done but when i make the call then it first render the normal code but after the api call it's not re-render the fetched data.

enter image description here enter image description here

please describe me the problem and how can i solve this as i am beginner in the react.


Solution

  • Try adding a null check whenever you are calling map function.

    filteredRestaurant?.map(x => <RestaurantCard  />)