6 ms·
Atoms have a few advantages over a plain object: 1. They can easily provide derived data without manual memoization. 2. You can provide custom setters that do
by cageface 2y ago
Atoms have a few advantages over a plain object:
1. They can easily provide derived data without manual memoization.
2. You can provide custom setters that do more than just assign values.
3. Your UI only re-renders the parts that reference fields that changed, not every component.
4. Atoms compose nicely etc.
Putting plain JS objects in context/state and passing them around only really works for simple, small apps. Beyond that you need more powerful tools. I also like Zustand for this.
- Rohansi 2y agoFor a bare object sure. Points 2 and 3 are solved with react-class-model. I don't understand how atoms compose nicely but classes wouldn't. Zustand looks a bit better but it is still very different from normal JS. Nobody writes code like that normally. Why can't we have normal, boring code for state management?
- cageface 2y agoThis react-class-model? https://github.com/Facepunch/react-class-model https://github.com/Facepunch/react-class-model 7 stars on github? Class objects with decorators? No thanks.
- Rohansi 2y agoThat's the one. Obviously not popular since I made it for an app I work on. What's wrong with decorators? Technically not needed but I like things being explicit.