When moving pages through NavLink
, most of the memory leak warnings disappeared when the cleanup function was used. However, when using react-redux
, a memory leak warning occurs.
How do I create a cleanup function to get rid of this warning message?
My code is here. For this code, using useState
instead of useDispatch
made the warning go away.
function List() {
const [isShow, setIsShow] = useState(false);
const dispatch = useDispatch();
const list = useSelector((state) => state.list);
useEffect(() => {
async function load() {
await dispatch(loadlist());
setIsShow(true);
}
let clean = true;
setIsShow(false);
if (clean) load();
return () => (clean = false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
if (isShow) return <Table data={list} />;
else return <Loading />;
}