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)
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 ofconst 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)
correct. If at any time you return a new object it will prevent this problem.