Warning: 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().
前几天写码遇上了这个问题, 网上找了半天也没啥头绪。
无意中看到这个
![](https://img.haomeiwen.com/i19245422/c014308041ad6183.png)
忽然醒悟到,这尼玛并不是setState呀, 并没有回调这说法的。
同时这个方法依赖的 state 也没写到useEffect的依赖中,
hooks 好多的错误可以参考这篇官网的: 在依赖列表中省略函数是否安全?
这本小书非常值得看:
https://overreacted.io/zh-hans/a-complete-guide-to-useeffect/
网友评论