我有一个函数,可以在单击时设置useState,一切正常,但是每次都会收到警告:
Line 22: The 'handleClickOpen' function makes the dependencies of useEffect Hook (at line 20) change on every render. To fix this, wrap the 'handleClickOpen' definition into its own useCallback() Hook react-hooks/exhaustive-deps
这是我的代码:
useEffect(() => {
axios.get("/api/getBlacklist/").then(data => setBlacklistItems(data.data));
// eslint-disable-next-line
}, [handleClickOpen]);
function handleClickOpen() {
setOpen(true);
}
我尝试仅用handleClickOpen
来替换useEffect
中的setOpen(true)
,但是由于重新渲染太多,页面崩溃了。
如何处理这种情况?
答案 0 :(得分:3)
每个渲染都会创建新的var result = inputList
.Where(i => Regex.Match(i, @"\baaa\.[a-z0-9]+")?.Success)
// or even
// .Where(i => Regex.Match(i, @"\ba+\.[a-z0-9]+")?.Success)
函数。您可以通过handleClickOpen
useCallback