Skip to content

Instantly share code, notes, and snippets.

@lukebrandonfarrell
Created October 3, 2019 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukebrandonfarrell/c2b9534a22688dcc60a0e622107b1012 to your computer and use it in GitHub Desktop.
Save lukebrandonfarrell/c2b9534a22688dcc60a0e622107b1012 to your computer and use it in GitHub Desktop.
const counterValue = 0;
const initialCounterValue = useInitialValue(selectedBrands);
const hasCounterChanged = counterValue !== initialCounterValue;
/**
* Use initial value
*
* @param value
*
* @return {*}
*/
export function useInitialValue(value) {
const initialValue = useRef(null);
useEffect(() => {
initialValue.current = value;
}, []);
return initialValue.current;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment