Skip to content

Instantly share code, notes, and snippets.

@KacperKozak
Last active February 27, 2025 22:24
Show Gist options
  • Save KacperKozak/733562fe02969919d18d17ead93b84ca to your computer and use it in GitHub Desktop.
Save KacperKozak/733562fe02969919d18d17ead93b84ca to your computer and use it in GitHub Desktop.
import { useMemo } from 'react';
/**
* A hook that returns a memoized version of the given object or array.
* **Important!** Use only if the object structure or array length is not changing!
*
* @example
* ```ts
* const api = useStructMemo({ query, setQuery, count });
* ```
*/
export const useStructMemo = <T extends object>(obj: T) => {
return useMemo(() => obj, Object.values(obj));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment