TypeError: map is not a function, in my reactJS code

Hello everyone, I’m fetching a data from an API and I keep getting stuck when I try to map the response and display my data… I still don’t know why I’m getting this error because I thought I’m getting back an array of object as my response


Y’all input will be greatly appreciated!

Do you know when useEffect triggers? When is it called with respect to render? Think about these questions for a minute.

Next, when this renders for the first time, what is the type of products in your state? Empty string right? That is because you say useState is an empty string. Try making that an empty array instead. Especially since you are relying on your products variable always being an array to use map on it. :slight_smile:

1 Like

Hi :),
next time, try to copy and paste here the original code. If you want to debug why you get the error, start to console the data (console.log(data)), probably is empty array or null etc.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.