Question

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.

No correct solution

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
scroll top