DEV Community

Cover image for React should change the documentation to React Hooks
alesbe
alesbe

Posted on

React should change the documentation to React Hooks

React Hooks came out around 4 years ago, and almost any React project made today uses functional components and hooks instead of the class-component model.

functional component

If we go to React's documentation a lot of explanation is done using class components, and they don't introduce hooks in the Main Concepts section, don't even mention it in the handling events page.

I think that mixing functional and class components can be misleading and confusing to anyone that wants to learn React as a first JS framework, also frameworks like NextJS made all the documentation using Functional Components.

I'm not saying that people shouldn't learn how to use class components, all the react projects that came out more than 4 years ago use them, but when I learned React some years ago I encounter this issue.

Would you change something about the documentation?

Oldest comments (14)

Collapse
 
andrewbaisden profile image
Andrew Baisden

Yes I have noticed that. They should update the documentation and have a legacy section for the Class syntax.

Collapse
 
ivan_jrmc profile image
Ivan Jeremic

I guess you missed it, they are already building the new docs with hooks. beta.reactjs.org/

Collapse
 
alesbe profile image
alesbe

Oh I didn't see that, it's a hundred times better! Hopefully they release this as standard documentation shortly!

Collapse
 
brense profile image
Rense Bakker

Yes, they should change it OOP is dead, functional programming is all teh rage now!

Collapse
 
harshrathod50 profile image
Harsh Rathod • Edited

I learnt React while only utilising the Class Components. It took me a while to accept the Functional Components and the wonders they have to offer. Now I always prefer Functional Components over Class Components. They should have more examples on the way Functional Components can be abused/toyed/utilised.

Collapse
 
the_riz profile image
Rich Winter

Instead of complaining, do the editing yourself and make a pull request (see "edit this page" at the bottom of the page)!

Collapse
 
alesbe profile image
alesbe

It's not about making a PR to update the docs, React team is building an updated version of the docs using functional components. Some PRs and issues mentioning exactly this were made before, for example here, here, and here. I'm just saying that it's been 4 years since functional components came out and new people coming to React will learn using the old classes instead of the new functional components. The project is open source but managed by Meta not by the community, I think that the documentation should have change some years ago. It's just a subjective opinion!

Collapse
 
thebearingedge profile image
Tim Davis • Edited

I'm curious about which you learned first? I've never met a new react dev that didn't need a lot of hand holding when going straight to hooks. Admittedly anecdata, but myself and several friends who took on mentees have experienced this. In the cases when I was asked which I teach first and responded "classes", it was meet with surprise. A few weeks later I got reports that mentees could not use hooks properly within a few days but when"downgraded" to classes finally got traction.

Hooks are fine, but they are magical. Nothing about them makes react more "functional".

I used to say that React to rewarded strong JavaScript fundamentals whereas something like Angular demanded framework expertise. Hooks ended that.

Will I use hooks? Yes. Will I teach hooks? Eventually. But they are a pedagogical nightmare.

Collapse
 
alesbe profile image
alesbe • Edited

I learnt functional components first (and then hooks). To be honest, I didn't need to use classes since I started with react, maybe because I didn't had to work with a relatively old react project.

In my case I self-taught react, it was my first JS framework, and I tried to learn using react docs, but encounter a lot of confusion because I didn't know which component style should I use, because functional components were relatively new, but every example was made using class components, but at the same time every react project made since then was made using functional components (or at least every project that I encounter), so I had a bit of confusion.

At the end, I ended up learning using other resources because the official documentation was so confusing at that moment, maybe because the hooks update was relatively new.

Finally, React decided to develop a beta version of the docs, that version will replace the actual one with purely functional components and hooks, and the current one will be moved into a "legacy" version, but not the official one.

It's been 4 years since the update came out, and being a framework created by Meta (Facebook) I don't really understand why they didn't change the docs already.

It's just my own experience! Maybe some people didn't have any issues at all!

Collapse
 
thebearingedge profile image
Tim Davis

Ok that all makes sense thanks for sharing 👍

Collapse
 
ivan_jrmc profile image
Ivan Jeremic

Class components are horrible trust me there is no magic in hooks, It just makes sense and I'm happy we have them.

Collapse
 
thebearingedge profile image
Tim Davis

I've no need to trust you, homie. I'm also happy for you and your amazing journey.

Thread Thread
 
ivan_jrmc profile image
Ivan Jeremic

You don't need to trust me, trust the people building React.

Thread Thread
 
thebearingedge profile image
Tim Davis

Think for yourself.