Answers for "dispatch on unmount"

0

dispatch on unmount

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
  };
}, []);
Posted by: Guest on June-09-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language