Reactjs.org: Docs - sample code updates needed?

Created on 23 May 2019  路  4Comments  路  Source: reactjs/reactjs.org

There seems to be confusion on how to write class components in the docs. Using this as a starting point for other pages which may need to be updated.

There is a mixture of function declaration and class components in the docs which can be confusing as when someone may __want__ or __need__ to use either method. Since the release of hooks, the docs should have a new site version release (similar to how Babel has site versions) with the updated, preferred way to write components backed by the core team.

in CONTRIBUTING.md, it shows that you should write classes with a constructor, but the Blog post titled "Update on Async Rendering" seems to prefer the former method of writing components.

Can this be solidified and added to the docs where necessary? Will there be a need to have a new site version with focus on function declaration components?

馃

Most helpful comment

@rachelnabors:

@alexkrolick mentioned that you are leading the docs project, so will you please share your plans for updated documentation? I started learning React after the hooks API was implemented. I, too, found it confusing that many parts of the documentation explain topics only from the perspective of class components, but the hooks section encourages using function components for all new code:

Should I use Hooks, classes, or a mix of both?

When you鈥檙e ready, we鈥檇 encourage you to start trying Hooks in new components you write.
...
In the longer term, we expect Hooks to be the primary way people write React components.

All 4 comments

There are 2 things here:

  • Regarding class components: In general the preference is still to use only standardized ES syntax unless specifically calling out that the syntax is still in proposal stage. Hence the recommendation to use constructor instead of class property syntax. This recommendation is not changing at the moment.
  • Regarding function components w/hooks vs classes: @rachelnabors from the core team is now leading the docs project and could probably comment on any plans to change over the recommendations to the new APIs, among other improvements and re-organizations.

thanks @alexkrolick! I'll look forward to any updates on the docs!

@rachelnabors:

@alexkrolick mentioned that you are leading the docs project, so will you please share your plans for updated documentation? I started learning React after the hooks API was implemented. I, too, found it confusing that many parts of the documentation explain topics only from the perspective of class components, but the hooks section encourages using function components for all new code:

Should I use Hooks, classes, or a mix of both?

When you鈥檙e ready, we鈥檇 encourage you to start trying Hooks in new components you write.
...
In the longer term, we expect Hooks to be the primary way people write React components.

Duplicate of #1788

Was this page helpful?
0 / 5 - 0 ratings