DEV Community

Discussion on: React Hooks: useMemo

Collapse
 
xinyan_yu profile image
Chinita Y

1 Hey! Nice article thankyou! However i would like to ask about the array after arrow function[userLists]? Any difference when i provide 1. no array, 2. empty array and 3 meaningful array like you did?

Collapse
 
afozbek profile image
Abdullah Furkan Özbek

In that scenerio;
1- if there is no array meaning userList is undefined or null we need to check before applying map function. In that case we can return [] so it will not broke the code.

2- If it is empty array meaning [] this should be ok because it is an Array instance so it will just return [].

Did this make it clear or you were asking something else

Collapse
 
xinyan_yu profile image
Chinita Y

Yes that was clear, thank you!
I wanted to ask this question because when using useEffect, array or no array makes difference on rendering. Just wondering if that‘s the same with useMemo :)