DEV Community

Discussion on: Referential Equality in React

Collapse
 
alexkhismatulin profile image
Alex Khismatulin

Great example!
But I guess it could be solved on the transformFn level. You didn’t show the implementation but I guess you mutate an object inside instead of returning a new one. For example, instead of
const transformFn = (memo, item) => { memo[item.key] = item.value; return memo; }
It should be
const transformFn = (memo, item) => ({ ...memo, [item.key]: item.value })

But it might lead to memory problems if you have a really long list(that I don’t think the case)

Collapse
 
tylerthehaas profile image
Tyler Haas

correct. If at any time you return a new object it will prevent this problem.