Re:Designing simpler React components
by tracker1 on Sunday March 27, 2016 @01:32PM
(#11370699)
I'd go a step further than mentioned... as static render components (single functions) are possible... if you're using something like redux/connect, you can export the static function, along with the default of the connected version. By doing this you have really straight forward testing, and don't even have to deal with the variance of class/object instances. I've build a few apps at this point using only static components.
Also, there are options to use immutable for state with redux (it's a little different), but it can be useful, to say the least.
The only downside of static components is that hot module replacement doesn't seem to work right, there are ways around it, but not as much fun... that said, I tend to save state to sessionStorage on every change, loading from sessionStorage at start, so refreshing the browser will just show the updated rendering.
Also, there are options to use immutable for state with redux (it's a little different), but it can be useful, to say the least.
The only downside of static components is that hot module replacement doesn't seem to work right, there are ways around it, but not as much fun... that said, I tend to save state to sessionStorage on every change, loading from sessionStorage at start, so refreshing the browser will just show the updated rendering.