0

New to React and JS. I've seen the answers relating to the issue of updating a single item in a state's list here, and I understand there is an emphasis/importance to the principal of not changing state directly.

I now want to know if there is a more efficient way to update such a single item in the state, while still adhering to this principle. All of the answers given at the very least perform a shallow copy of the list, then update the list. This seems pretty inefficient, especially in cases where the index/item that we want to update is known. All we want to do is update a single item while letting React know about it, why should we have to copy the whole list..

I haven't tested, but I'd imagine for very large lists this would cause stuttering. I'm definitely not the first person to be bothered by this, so I'm guessing maybe it doesn't matter as React has to iterate over the whole list anyhow to check which DOM elements need to be updated? (So therefore efficiency in this case is a lost cause?)

I've found a somewhat-related issue addressed here, but it is in regards to not wanting to re-render the whole list in the DOM. From the answers there, it seems maybe any lag/stutter will only be caused by re-rendering.

Perhaps my question is futile..

  • Possible duplicate of https://stackoverflow.com/questions/28010444/react-efficient-updating-of-array-state – Hbarna Oct 02 '19 at 08:54
  • 1
    it should not be an issue if each item has its own state, but you have to post the changes to your end for each item then. > advise : do not optimize the performance unless you facing a performance issue other than that it's a waste of time – Eslam Abu Hugair Oct 02 '19 at 09:09

0 Answers0