3 ms·
I’ve been writing a lot of react over the past several years (JS/TS), and I strongly agree with this take: hooks, especially hooks like useState really are an a
by fiddlerwoaroof 6y ago
I’ve been writing a lot of react over the past several years (JS/TS), and I strongly agree with this take: hooks, especially hooks like useState really are an attractive nuisance that, by making it easy to have local state in components, end up spreading business logic all over the view layer and coupling all the wrong things together.
- raspasov 6y agoAgreed. I would not use local state apart from fine-grained performance optimizations or temporary, always-can-be-thrown-away state specific to the component itself. Example: email field input before passing validation.
- fiddlerwoaroof 6y agoI’ve had the experience, though, that “temporary” state often becomes a feature requirement. Like, you have a field to search your dataset by email address and, next iteration, the product manager wants autocomplete based on partial input.
- raspasov 6y agoThe autocomplete results can come from the global app state. There’s no rules written in stone about what should be in local state. My default is “as little as possible”.
- fiddlerwoaroof 6y agoMy point is that I’ve found that there is very little local state that doesn’t eventually benefit from being merged into the global state management store.
- raspasov 6y agoFair enough.