DEV Community

Discussion on: useEffect firing twice in React 18

Collapse
 
shivamjjha profile image
Shivam Jha

The issue is when you call useEffect for this, this will not happen during initial render phase.

State set -> react realizes it needs to fire an effect -> usEffect runs -> state set again (filteredItems) -> re render

So you see this is not very performant.
While if you use useMemo (or just simply calculate result without memo), react can calculate result during render which is more desirable