Skip to content

Instantly share code, notes, and snippets.

@CryceTruly
Created December 16, 2020 05:08
Show Gist options
  • Save CryceTruly/b8260e6a9c4e9eaa04c69040199ec302 to your computer and use it in GitHub Desktop.
Save CryceTruly/b8260e6a9c4e9eaa04c69040199ec302 to your computer and use it in GitHub Desktop.
Implementing componentDidUpdate using hooks.
const initialItemsRef = useRef([]);
useEffect(() => {
if (userItems.length) {
const prev = initialItemsRef.current;
initialWalletsRef.current = <whatToCheckForChanges>;
const newones = initialItemsRef.current;
if (newones.length - prev.length === 1) {
const difference = newones.find((x) => !prev.map((i) => i.AccountNumber).includes(x.AccountNumber));
// dome stuff here
}
}
}, [whatToCheckForChanges.length]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment