-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from complexdatacollective/feature/alternate-b…
…eforeNext Feature/alternate before next
- Loading branch information
Showing
58 changed files
with
1,023 additions
and
1,638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable no-console */ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
export default function useWhatChanged(props: Record<string, unknown>) { | ||
// cache the last set of props | ||
const prev = useRef(props); | ||
|
||
useEffect(() => { | ||
// check each prop to see if it has changed | ||
const changed = Object.entries(props).reduce( | ||
(a, [key, prop]: [string, unknown]) => { | ||
if (prev.current[key] === prop) return a; | ||
return { | ||
...a, | ||
[key]: { | ||
prev: prev.current[key], | ||
next: prop, | ||
}, | ||
}; | ||
}, | ||
{} as Record<string, unknown>, | ||
); | ||
|
||
if (Object.keys(changed).length > 0) { | ||
console.group('Props That Changed'); | ||
console.log(changed); | ||
console.groupEnd(); | ||
} | ||
|
||
prev.current = props; | ||
}, [props]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.