Object Oriented React
-
-
I am not versed in React but I do know that it uses component-based structures (which is the new OOP I believe). You can apply OOP but that is outside my scope.
-
I wouldn't recommend it. JS and TS aren't really geared for OOP, and while it can support it you'll be swimming upstream. There are cases where you can't really avoid it, like my finite automata JS lib, but prefer functions.
A component in React is like
function MyComponent() { ... }And react is bit funny about what it expects. For example components I think have to be PascalCase.
My point is, you may get away with it, but you'll be in for some surprises along the way probably. Personally, I don't like surprises.
It's not hard to not use OOP and prefer functions. It just takes a little practice. It's not so much learning new things as it is paring what you know. It's worth doing, or you're going to be spending a lot of your time pounding square pegs into round holes.
-
Does anyone use OOP in their react apps? Does it make it easier?
The app I'm working on right now is implemented using function programming, and after 30 years of OOP dev work, I find it frustrating to have to go what I feel is backwards.
@realJSOP I have done some OOPs with TypeScript, but the JavaScript generated wasn't so much.
I googled to see articles on pros and cons:
There are some interesting articles on these two searches. It looks possible with TypeScript, while JavaScript is primarily a prototype-based language.