dispatch on unmount

Solutions on MaxInterview for dispatch on unmount by the best coders in the world

showing results for - "dispatch on unmount"
Ian
31 Feb 2017
1const [userCheck, setUserCheck] = React.useState('');
2
3const userCheckRef = React.useRef(userCheck); // ref to store state value
4
5React.useEffect(() => {
6  userCheckRef.current = userCheck; // save userCheck state value to ref
7}, [userCheck]);
8
9...
10
11useEffect(() => {
12  return () => {
13    dispatch(saveFetchValue(userCheckRef.current)); // pass current ref value
14  };
15}, []);
16
queries leading to this page
dispatch on unmountdispatch on unmount