forked from donavon/use-persisted-state
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dequal): state of usePersistedState is now memoized
- Loading branch information
Dennis Morello
committed
Nov 9, 2020
1 parent
5652099
commit cd02ed9
Showing
2 changed files
with
25 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useRef } from 'react'; | ||
import { dequal } from 'dequal/lite'; | ||
|
||
const useMemoizedObject = (obj) => { | ||
const mem = useRef(); | ||
|
||
if (dequal(mem.current, obj)) { | ||
return mem.current; | ||
} | ||
|
||
mem.current = obj; | ||
return obj; | ||
}; | ||
|
||
export default useMemoizedObject; |
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