node.js - 警告:来自 useState() 和 useReducer() Hooks 的状态更新不支持 " + ... MERN 堆栈应用程序
问题描述
为什么我的 setUser 在我 console.log 时返回该警告?:
function dispatchAction(fiber, queue, action) {
{
if (typeof arguments[3] === 'function') {
error("State updates from the useState() and useReducer() Hooks don't support the " + 'second callback argument. To execute a side effect after ' + 'rendering, declare it in the component body with useEffect().');
}
}
这是功能:
const UserContextProvider = (props) => {
const [user, setUser] = useState({})
useEffect(() => {
fetch(`${API}/auth/user`, {
method: 'GET',
withCredentials: true,
credentials: 'include'
})
.then (response => response.json())
.then (response => {
setUser(response.user)
console.log(setUser)
})
.catch (error => {
console.error (error);
});
}, [setUser])
注意: response.user 只是一个对象。而且我可以访问用户中的数据,而子组件中没有问题。
解决方案
推荐阅读
- rust - Rust 中的期货向量不会同时执行
- mysql - csv文件上传的存储过程问题
- machine-learning - 如何在 ML 中保存特征工程模型
- python - 更新嵌套的 Django 对象,如果下一个对象不存在,则创建一个新对象
- python - 加载模型时出现内存错误
- flutter - 如果 appbar 为空,ListView.builder 显示可用空间
- php - 如何在 PHP 中的特定数组键之前排列数组
- javascript - 将高度缩小到内容大小
- html - 如何使用 css 在方框中创建动画波浪?
- python - 使用 Python Selenium 从弹出窗口中提取内容