Created
September 19, 2020 15:53
-
-
Save david-arteaga/565bf9c42b7d7af1e3a5018c93dc054e to your computer and use it in GitHub Desktop.
[useMemoedObjectLiteral] #react #typescript #memoed
This file contains hidden or 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
import { useMemo } from 'react'; | |
/** | |
* Memoize an object based on it's keys and values. MAKE SURE the object always has the same | |
* keys and values | |
* @param object An object that will always have the same number of properties | |
*/ | |
export default function useMemoedObjectLiteral<T>(object: T): T { | |
return useMemo(() => object, Object.values(object)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment