请教一个关于 useEffect 依赖的问题
最近在学习 react 和 nextjs ,算初学者,感觉我写的很多 useEffect eslint 都提示缺少依赖,但其实我觉得写的依赖已经够了
比如这样
const [conversation, setConversation] = useState<Conversation[]>([]) useEffect(() => { if (currentChatTitle) { setConversation( conversation.map((i) => { return { ...i, title: i.id === currentChatId ? currentChatTitle : i.title, } }) ) } }, [currentChatId, currentChatTitle]) eslint 就说缺少conversation这个依赖,但是加了之后就无限执行这个 useEffect 回调了,其实我连这个currentChatId都不想加入依赖
eslint 也给了解决方案就是改成setXXX((prev)=>xxx),但这样好麻烦啊,或者就是 disable 掉这一行
useEffect(() => { if (currentChatTitle) { // 改成`setXXX((prev)=>xxx)` setConversation((conversation) => conversation.map((i) => { return { ...i, title: i.id === currentChatId ? currentChatTitle : i.title, } }) ) } }, [currentChatId, currentChatTitle]) 请问下各位平时会关掉这个eslintreact-hooks/exhaustive-deps这个规则吗

