How to setState by value in React?
4 answers
There is no way to further minify the code with the current ECMAScript version. Perhaps with ES6 it is possible, depending on what features the language has.
However, if you are worried about code redundancy, you can add this method to mixing and pass it across all the components you need.
Update: Thanks to @FakeRainBrigand for providing ES6 syntax that allows you to shrink your code:setState({[name]: value});
+3
source to share
If you are using a function thingChanged
to bind two-way data, LinkedStateMixin can help you do this with less code.
0
source to share