Last active
April 22, 2022 20:22
-
-
Save LucasCalazans/8a3ebbef73547ec072e0490af0c58dd1 to your computer and use it in GitHub Desktop.
useMemo example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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