28 ms·
I fully agree that impure views are a path to madness, but you don’t have to abandon React to have pure views. React components can, and I would argue in vast
by branko_d 4y ago
I fully agree that impure views are a path to madness, but you don’t have to abandon React to have pure views.
React components can, and I would argue in vast majority of cases should, be pure functions. You just need to displace state management outside of React.
This removes the need for class components and hooks and returns React to its roots as a view library. Most complications in React seem to stem from its desire to also be a state library.
Case in point: we used MobX with React to build a UI for an entire document management system (essentially a file system with versioning, security and workflows) - I don’t think we have more than a handful of impure React components in the entire codebase.
- marcosdumay 4y agoInterestingly, the optimal place I see to keep state is inside the reactive system. You just have to ensure that every single non-pure action is notated as an event. You can even have a lot of pure state interdependence. What React doesn't even try (because yes, it's a view library). Anyway, one can certainly keep all views pure. It's a bit hard in Javascript where a lot of things are hidden, but it's perfectly doable. It's even the recommended way to use React. But that doesn't save React from being way larger, slower, and harder to use than it could otherwise be.