Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs to use hooks #1788

Closed
selbekk opened this issue Mar 5, 2019 · 22 comments
Closed

Update docs to use hooks #1788

selbekk opened this issue Mar 5, 2019 · 22 comments

Comments

@selbekk
Copy link
Contributor

selbekk commented Mar 5, 2019

As of now, the main docs haven’t been updated to account for hooks. Especially the state & lifecycle section seems a bit misleading now.

I’d love to help out with a rewrite, but I’d love to hear your feedback on what should be changed and what should stay behind.

@saranshkataria
Copy link
Member

Since we are having the discussion at #1782, closing this one out.

@selbekk
Copy link
Contributor Author

selbekk commented Mar 5, 2019

Slightly different issue @saranshkataria - this pertains to the docs, not the tutorial

@saranshkataria
Copy link
Member

ah, my bad. But why would we want everything to be hooks in the docs? There's a section about hooks and that is what it should be?

@selbekk
Copy link
Contributor Author

selbekk commented Mar 5, 2019

On mobile now, but in short: if the Preferred Way of React going forward is using hooks for stuff like state and side effects, I think we should rewrite the docs so that they mirror that message. Right now, that’s not the case.

Have a look here: https://reactjs.org/docs/state-and-lifecycle.html

Class components and lifecycles definitely need to be documented, but perhaps not as... «the first choice», if you know what i mean.

@saranshkataria
Copy link
Member

I don't think the docs should be preferring one way over the other yet, everyone is still figuring hooks out, but will reopen this issue to let other people share their opinions on it.

@saranshkataria saranshkataria reopened this Mar 5, 2019
@selbekk
Copy link
Contributor Author

selbekk commented Mar 5, 2019

As of now, though, the docs are preferring class components, by not even mentioning hooks (at least in that section)

@kachkaev
Copy link

kachkaev commented Mar 10, 2019

RADME.md in facebook/react repo says:

We have several examples on the website. Here is the first one to get you started:
[a functional component]

Following the link takes a newcomer to a page where all components are classes. This is quite confusing. Given that the stateful logic can be expressed using hooks now, classes can be revealed much later.

@voluntadpear
Copy link

I feel the same about the Main Concepts docs. Especially the "State and Lifecycle" doc. I was expecting to see at least a mention about Hooks there. Newcomers to React (especially folks coming from other libraries) could choose to check the Docs instead of the Tutorial (depending on their style of learning) so the Hooks section being after Advanced Guides and even the API Reference makes them somehow easy to miss. Having a brief mention of Hooks as an alternative to classes could be really helpful.

@nickmccurdy
Copy link
Contributor

nickmccurdy commented Sep 26, 2019

@saranshkataria

I don't think the docs should be preferring one way over the other yet, everyone is still figuring hooks out, but will reopen this issue to let other people share their opinions on it.

The hook docs recommend using hooks rather than classes for new components (see Should I use Hooks, classes, or a mix of both?). The docs should primarily focus on hooks to be consistent with this suggestion, and save time by not requiring users to learn classes before they can learn hooks.

With docs rewritten in hooks, we'd have to decide how to handle the old class docs. Is the class API going to change in the future, making it useful to maintain the original class docs in full as a separate verison? If not, should we stop updating the class docs or move them to a subsection of the hook docs (kinda like how hook docs are a subsection of the class docs now)?

@nickmccurdy
Copy link
Contributor

I'm making progress on converting the docs to use hooks instead of classes, and I'll submit a pull request when it's mostly complete. Then we can figure out if it's okay to replace the class docs or if the hook docs should be reworked in a different way.

@nickmccurdy
Copy link
Contributor

I've started a draft pull request, I'm not done checking it for accuracy but I'd still appreciate feedback: #2400

@jasongi-actu
Copy link

Since hooks are such a big change, and many people will be needing to learn react using classes, is it an option to provide examples, one using hooks and one using classes? Perhaps tab separated or something? I think this would also aid with people who want to refactor class code to functional components, as well as ensuring new code projects and people new to react start off learning hooks.

@nickmccurdy
Copy link
Contributor

nickmccurdy commented Feb 6, 2020

I don’t think that’s a good idea because the hook API is designed very differently. There’s some overlap with some usages of hooks and classes, but there are enough differences and quirks that I think it would be easiest to explain them separately. There are already some references that compare basic hook usage with basic class usage anyway.

Also the React team is planning on rewriting the docs from scratch fo hooks anyway, so the structure is going to differ (as it should because they don't really translate to each other directly).

@karlhorky
Copy link
Contributor

In case this can be useful to anyone else:

@nickmccurdy's incomplete but very useful version of the docs with React hooks is online at https://reacthooks.nickmccurdy.com

@kachkaev

This comment has been minimized.

@gaearon
Copy link
Member

gaearon commented May 15, 2020

Just wanted to note this is still very much on our minds. We might start looking into this soon-ish. One challenge is how to coordinate translations. Since this is a big rewrite. cc @tesseralis curious if you have tips on how we could approach this.

@kachkaev
Copy link

kachkaev commented May 15, 2020

@gaearon when replacing class components with the function ones in the docs, is the plan to use function MyComponent() {} or const MyComponent = () => {}? I guess that there should be some agreed on guidelines before the process starts. The chosen flavour will have a pretty significant impact on the community for years to come, so it should be picked very carefully.

It'd be great if this thread included a link to the guidelines (or their ongoing discussion). That feels quite relevant.

@gaearon
Copy link
Member

gaearon commented May 16, 2020

I don't think there would be any significant impact given we've used function since 2013 and people sometimes prefer arrows anyway.

@tesseralis
Copy link
Member

@gaearon I don't think there should be a significant problem, although it might cause a headache with some languages that aren't as active. I'll check in over the weekend and see if there are any issues and see what's the best way to communicate this change to people.

@koba04
Copy link
Member

koba04 commented May 25, 2020

I think "Tutorial" is the highest priority than others because beginners would check the Tutorial page first. I don't want to recommend beginners the current Tutorial page because the Tutorial is written based on class components.
I believe that React is going forward to the Hooks world, so I'd like to teach beginners how to create components with Hooks at first rather than class components API even though they might learn class components API for existing components later.

It needs many works for translation, but it shouldn't block the migration.

@nickmccurdy
Copy link
Contributor

nickmccurdy commented Apr 20, 2021

If anyone finds it helpful in the meantime, there's a newer fork of the docs that's more up to date than mine: https://reactwithhooks.netlify.app/

@harish-sethuraman
Copy link
Collaborator

React documentation is currently being rewritten from scratch and is a WIP.
Do checkout https://beta.reactjs.org and let us know your feedback in the following issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.