Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brunocarvalhodearaujo/de9935b03dfd3ac3f827270a82cbabd3 to your computer and use it in GitHub Desktop.
Save brunocarvalhodearaujo/de9935b03dfd3ac3f827270a82cbabd3 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