Skip to content

Instantly share code, notes, and snippets.

@david-arteaga
Created September 19, 2020 15:53
Show Gist options
  • Save david-arteaga/565bf9c42b7d7af1e3a5018c93dc054e to your computer and use it in GitHub Desktop.
Save david-arteaga/565bf9c42b7d7af1e3a5018c93dc054e to your computer and use it in GitHub Desktop.
[useMemoedObjectLiteral] #react #typescript #memoed
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