Skip to content

Instantly share code, notes, and snippets.

@LucasCalazans
Last active April 22, 2022 20:22
Show Gist options
  • Save LucasCalazans/8a3ebbef73547ec072e0490af0c58dd1 to your computer and use it in GitHub Desktop.
Save LucasCalazans/8a3ebbef73547ec072e0490af0c58dd1 to your computer and use it in GitHub Desktop.
useMemo example
const categories = useMemo(() => {
return products.reduce((categories, { category }) => {
return !category || categories.find(({ id }) => category && category.id === id)
? categories
: [
...categories,
{
id: category.id,
value: category.id,
label: category.title,
},
];
}, [])
}, [products]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment