如何解决警告:来自 useState() 和 useReducer() 钩子的状态更新不支持“ + ... MERN Stack Application
为什么我的 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 只是一个对象。而且我可以在子组件中访问用户中的数据而没有问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。