DEV Community

francajosejunior
francajosejunior

Posted on

Checking item by reference of object

Today, I realized that I dont need to use a id property in a object to check what item I want changing in a array...
I just pass the reference of object, and when I did a strict comparation... 😱

this.state.list.map(x => {
   // checking item by ref
   if (x === item) {
      return { ...item, count: (item.count || 0) + 1 };
   }
   return x;
})

It works!!!

I don`t known if it is bad to performance, but I think it is easy to code.

What do you think about this approach?

See on CodeSandbox

Top comments (0)