DEV Community

Discussion on: Immutibilty

Collapse
 
miketalbot profile image
Mike Talbot ⭐

A very good point from my perspective on legibility. A key thing here is using stack based variables that have super low cost, so no point following my argument there. You can have many stack based variables without fearing a garbage collection glitch or a complex memory management operation.

So for clarity on my comment in light of this point, I'm suggesting that:

    something.state = {...something.state, x: something.state.x+1}

If you do it frequently is a bad idea for performance reasons due to the amount of memory being stored up for collection. It's also a bit less legible than:

   something.state.x += 1