I got a problem userData.map is not a function
TypeError: userData.map is not a function error Try changing again, error still doesn’t improve I encountered a problem userData.map is not a function TypeError: userData.map is not a function I tried changing variables but still no error. In the past, I used another computer to run normally. When I moved to this machine, I encountered no error. Are you sure from which part
2
Answers
Just move
console.log(userData)
fromuseEffect
to JSX to be able to see whatuserData
looks like in each component render.First time it will output
[]
and the error does not appear, then in the next render it will output the new value ofuserData
which is not an array souserData.map is not a function
come.we are sure that
userData
is updated becauseuserData.map is not a function
does not happen whenusrData
is[]
.Your endpoint is probably returning an object not an array, inside this reponse, you may find your array so then you set it to
setUserData()
.This has nothing to do with your different machines.
I have the same problem the fix was to put a ? before .map userData?.map