📅  最后修改于: 2022-03-11 15:01:50.645000             🧑  作者: Mango
const [userCheck, setUserCheck] = React.useState('');
const userCheckRef = React.useRef(userCheck); // ref to store state value
React.useEffect(() => {
userCheckRef.current = userCheck; // save userCheck state value to ref
}, [userCheck]);
...
useEffect(() => {
return () => {
dispatch(saveFetchValue(userCheckRef.current)); // pass current ref value
};
}, []);