-
-
Save brunocarvalhodearaujo/de9935b03dfd3ac3f827270a82cbabd3 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