ianstormtaylor / react-values

A set of tiny React components for handling state with render props.
https://git.io/react-values
MIT License
1.02k stars 39 forks source link

Don't mutate "value" #5

Closed theKashey closed 6 years ago

theKashey commented 6 years ago

Some operations, like array.sort do mutate original value. I know, that you are aware of it, but why do you returning muted value, not mutated copy of the value? Current approach probably could poison render, as long it may change value during the render.

ianstormtaylor commented 6 years ago

Hey @theKashey thanks for opening this too.

I wasn't really sure what the best thing to do here was. I think I avoided it because I wasn't sure if copying the values would end up with performance issues, but honestly that seems now like not the right decision. Whenever I used to use this.setState for things like arrays I'd always manually .slice() them myself, so that does seem like it would be the desired behavior!

ianstormtaylor commented 6 years ago

Released in 0.2.0!