Skip to content

Instantly share code, notes, and snippets.

@nirsky
Created December 25, 2018 12:41
Show Gist options
  • Save nirsky/cd5b8d2cd5570fa88668ce8be3de4c2b to your computer and use it in GitHub Desktop.
Save nirsky/cd5b8d2cd5570fa88668ce8be3de4c2b to your computer and use it in GitHub Desktop.
const Counter = props => {
const [count, setCount] = useState(0);
const prevCountRef = useRef();
useEffect(() => {
prevCountRef.current = count;
});
const prevCount = prevCountRef.current;
return <h1>Now: {count}, before: {prevCount}</h1>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment