NodeJS userData.map 不是函数TypeError:userData.map不是函数[已关闭]

sg2wtvxw  于 2023-05-22  发布在  Node.js
关注(0)|答案(1)|浏览(100)

**关闭。**此题需要debugging details。目前不接受答复。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答这个问题。
4天前关闭。
Improve this question
我遇到了一个问题userData.map不是一个函数TypeError:userData.map不是一个函数错误尝试再次更改,错误仍然没有改善我遇到了一个问题userData.map不是一个函数TypeError:userData.map不是一个函数,我尝试改变变量,但仍然没有错误。以前我用另一台电脑也能正常运行。当我移动到这台机器时,我没有遇到任何错误。你确定是从哪个部位
[ enter image description here ](https://i.stack.imgur.com/QYo8h.png

7vux5j2d

7vux5j2d1#

只需将console.log(userData)useEffect移动到JSX,就可以看到userData在每个组件渲染中的样子。

return (
<React.Fragment>
  {console.log(userData)}
</React.Fragment>
);

第一次它将输出[],并且错误不会出现,然后在下一次渲染中它将输出userData的新值,这不是一个数组,所以userData.map is not a function来了。
我们确信userData被更新了,因为当usrData[]时,userData.map is not a function不会发生。
你的端点可能返回一个对象而不是一个数组,在这个响应中,你可能会找到你的数组,所以你把它设置为setUserData()
这与你的不同机器无关。

相关问题