DEV Community

Discussion on: React: Lifting state up is killing your app

Collapse
 
bessemzitouni profile image
Bessem Zitouni • Edited

hello, thanks for this wonderful tutorial

can you tell me what's the difference in setCell function between :

this.data = [
      ...this.data.slice(0, rowI),
      [
        ...this.data[rowI].slice(0, cellI),
        newContent,
        ...this.data[rowI].slice(cellI + 1),
      ],
      ...this.data.slice(rowI + 1),
    ]

And

this.data[rowI][cellI] = newContent
Collapse
 
aigoncharov profile image
Andrey Goncharov

Hi Bessem!

The second one mutates the array, while the first one creates a brand new one. See reactjs.org/docs/state-and-lifecyc...