3 ms·
My experience with ReactJS has been the first time I felt I had the perfect balance of OOP and FP. The components are so well defined as objects since they hav
by Waterluvian 10y ago
My experience with ReactJS has been the first time I felt I had the perfect balance of OOP and FP.
The components are so well defined as objects since they have the luxury of being tangible. But using them in a pure manner with zero local state makes them so easy to reason about and reuse.
More can be said about Redux but I'll leave it there.
- domlebo70 10y agoWhat is OO about React though? You have data, and pure functions. Where does OO come into it?
- Waterluvian 10y agoYou can create components from functions or as classes. I will create a button class, which has some methods for how it renders and updates itself and how a user interacts with it. I can then subclass it to make a toggle button or whatever else. Say I have a form with 4 fields and a "Submit" button. The submit button's `onClick` tells its parent that it was clicked. The parent calls `getValue()` on all of its children (the form fields) and dispatches a `updateMyDatabase()` action. My example may be controversial to some as my form fields have state. Some may say that on every keystroke, the form should have an action called that updates the `centralState.formValue`. But regardless of that, I think it's still evident how there's OOP involved?
- deleted 10y ago[deleted]