Hacker News new | ask | show | jobs
by Our_Benefactors 250 days ago
> I can put that in a useMemo and it won't sort it again when the page eventually rerenders for some reason

useMemo dependency smell. This is almost always because your dependencies are wrong. This can often happen if you put a dependency as [object] instead of [object.field] due to how JavaScript maps objects to memory.

2 comments

Never thought of it that way. What if it's an array though, how will I put it as a dependency?
useMemo is quite nice when you're doing data transformation against some API call or other big data structure.
Yes, it is, but you still have to declare your dependencies correctly.