-2

Which is better to use? react class based stateful component or react hooks functional stateful component? I've searched a bit but couldn't find what is preferred to use.

1
  • Please describe the scenario and requirements (what are you needing to accomplish?)
    – Martin K
    Feb 7, 2020 at 12:18

1 Answer 1

0

There is really no concrete answer to this, but I can provide some information that might help you decide:

On https://reactjs.org/docs/hooks-faq.html they state

In the longer term, we expect Hooks to be the primary way people write React components.

So if you want to follow the future trends of React, this might be the better way to go.

On the other hand, they also state

We intend for Hooks to cover all existing use cases for classes, but we will keep supporting class components for the foreseeable future.

So really either way is valid, it is really your own preference as you can achieve the same results from both functional and class components.

In my experience, I have preferred hooks because I find it makes writing re-usable component logic a little easier and clearer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.