Skip to content

Instantly share code, notes, and snippets.

@aztack
Created April 15, 2024 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aztack/cba6c57d3ac67b016060c9ce3f5a3487 to your computer and use it in GitHub Desktop.
Save aztack/cba6c57d3ac67b016060c9ce3f5a3487 to your computer and use it in GitHub Desktop.
useArrayCompare
function useArrayCompare<T>(value: T[]) {
const ref = useRef<T[]>(value);
if (value.length !== ref.current.length ||value.sort().join(',') !== ref.current.join(',')) {
ref.current = value;
}
return ref.current;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment