|
|
|
|
|
by ohgodplsno
1252 days ago
|
|
Nothing in React (or any reactive language/library) prevents you from doing that. But if you're going to mutate state, make sure to notify it about it. Add an entry to your data ? Sure, just re-do a setState() after and you'll be good. But that requires you to make sure that every time you mutate state, you re-notify the UI of it. setState(data.map { d-> d.tree.map { d2 -> ... } })
is the exact same thing as data[5][6][2][4].addChild(file)
setState(data)
React people will tell you to only use immutable objects, do copies, etc, but if your usecase requires mutating data, just mutate the damn data. It's not all or nothing. And even if you want to work with purely immutable data, you can work with lenses and have everything you want. With any language that has proper typing, you don't even need to build lenses with "keyed" names and can get the proper types. |
|