6
orton
15d

In React, OOP is now the old way of approaching react.js everybody doing functional programming/functional components.. this that the future ???

Comments
  • 3
    Pure components are the best practice, yes.
  • 1
    Reactive frameworks stopped buying into OOP since forever.
  • 1
    Imagine unironically using react in 2020
  • 2
    On an unrelated note I rate this rant’s tags decent but sometimes something feels off. Overall strong 7/10 👍
  • 0
    @uyouthe I unironically use React in 2020.
  • 3
    I love my class components.

    As long as you aren't doing anything with state, functional is the way to go

    But it just feels more intuitive working with state in classes than in functions, and I've never had problems 'this' in my time with React

    I feel like hooks are a way to bring React to people who don't fully understand JavaScript, and don't really want to learn the oddities of the language
  • 4
    @10Dev I feel like that’s a harsh assessment. I know the oddities of the language better than most and still prefer functional components with hooks over class components. I definitely prefer them over prop drilling. Remember prop drilling? I hate prop drilling.
  • 1
    @10Dev I love functional components, less boilerplate and the components seem more explicit as far as what they are doing.

    I'm not sure I ever learned anything about JavaScript because I used a class component.
  • 6
    @AmyShackles
    There are people who understand separating data from functions, and people who like to watch the world burn.
  • 0
    hopefully
  • 2
    Hook are fun, I’m new to react but I’d much rather deal with useState and not have to worry about complex life cycle code like component did mount, didn’t mount, almost mounted but passed out
  • 0
    OOP is the new normal
  • 0
    @10Dev I prefer hooks since it results in cleaner, and smaller, code in my opinion.

    And I have been using js extensively since 1995 when Netscape released the first version ;)
  • 1
    @theabbie Eh? You straight out of 1999?
  • 0
    Lifecycle methods were easy to use, it took you like 10 minutes to read the friggin docs.

    Classes are ok, easier to test, but I also prefer hooks as code is cleaner.
  • 0
    @AlmondSauce I find it more structured
  • 1
    @theabbie If it's your preference then there's nothing wrong with that at all - but I'm not sure it's been considered the "new normal" for about 20 years :-)
  • 0
    @AlmondSauce Isn't that how multiple people work on same Project?
  • 1
    @theabbie Eh? Are you thinking of version control?
  • 0
    @AlmondSauce No, Reusable components and stuff, It is definitely more scalable than functional programming, if I understand what functional programming means
  • 1
    You can still reap the benefits of oop like encapsulation and separation of concerns with hooks and you won’t have to deal with extra typing and code fat. Lifecycle methods weren’t hard for me but add complexity I don’t need
  • 1
    @theabbie you can reuse functional components by importing them. Functional components are still objects and you can think of their props or parameters as object fields. I’m not sure how far you can really go with object oriented programming in react like using interfaces and polymorphism like in java
  • 0
    I'm still a beginner learning react. I've seen people use and teach class and function based components. Is there any significant difference between them why one is preferred over the other? Like performance wise etc?
  • 1
    @theabbie note: in JavaScript all functions are object they can have properties and behaviour
  • 1
    @firecracker Not really. It’s more of a preference and what you feel is easier for people reading your code.
  • 1
    Functional vs OOP is not a competition. There is a time and place to use either. A lot of things that react does benefits from using pure functions. Actually that applies to almost anything on the browser these days. But that's not taking away from OOP.
Add Comment