react项目经典报错 , 且一直弹出 Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render 原因 : 因为用useEffect监听的依赖项在每次渲染时都变化 , 触发了无限更新 , 也就是useEffect监听的依赖项和useEffect的内容不符 !!! useEffect(() => { if (isSelectAll) { setSelectedRowKeys(data.map(item => item.key)) } else { setSelectedRowKeys([]) } }, [selectedRowKeys]) // 写太快了,监听的依赖项写错了,应该是监听isSelectAll 就解决问题了 useEffect(() => { if (isSelectAll) { setSelectedRowKeys(data.map(item => item.key)) } else { setSelectedRowKeys([]) } }, [isSelectAll])