-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Update docs for stable Hooks #1593
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
Changes from 1 commit
08b6e4b
4d61b4a
f510e11
9d62821
eaefc81
57138d7
5da272a
e9081c7
d15ec6e
37d46dd
ee5fea9
e301239
2fd487e
ed6e711
0d89570
95258c0
e5a987b
d460a9b
f9f0d66
d97cdca
601c016
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ permalink: docs/hooks-faq.html | |
| prev: hooks-reference.html | ||
| --- | ||
|
|
||
| *Hooks* are an upcoming feature that lets you use state and other React features without writing a class. They're currently in React v16.8.0-alpha.1. | ||
| *Hooks* let you use state and other React features without writing a class. | ||
|
|
||
| This page answers some of the frequently asked questions about [Hooks](/docs/hooks-overview.html). | ||
|
|
||
|
|
@@ -19,7 +19,9 @@ This page answers some of the frequently asked questions about [Hooks](/docs/hoo | |
| --> | ||
|
|
||
| * **[Adoption Strategy](#adoption-strategy)** | ||
| * [Which versions of React include Hooks?](#which-versions-of-react-include-hooks) | ||
| * [Do I need to rewrite all my class components?](#do-i-need-to-rewrite-all-my-class-components) | ||
| * [What can I do with Hooks that I couldn't with classes?](#what-can-i-do-with-hooks-that-i-couldnt-with-classes) | ||
| * [How much of my React knowledge stays relevant?](#how-much-of-my-react-knowledge-stays-relevant) | ||
| * [Should I use Hooks, classes, or a mix of both?](#should-i-use-hooks-classes-or-a-mix-of-both) | ||
| * [Do Hooks cover all use cases for classes?](#do-hooks-cover-all-use-cases-for-classes) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I already edited that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry just saw that. I'll close that issue |
||
|
|
@@ -51,10 +53,27 @@ This page answers some of the frequently asked questions about [Hooks](/docs/hoo | |
|
|
||
| ## Adoption Strategy | ||
|
|
||
| ### Which versions of React include Hooks? | ||
|
|
||
| Starting with 16.8.0, React includes a stable implementation of React Hooks for: | ||
|
|
||
| * React DOM | ||
| * React DOM Server | ||
| * React Test Renderer | ||
| * React Shallow Renderer | ||
|
|
||
| Note that **to enable Hooks, all React packages need to be 16.8.0 or higher**. Hooks won't work if you forget to update, for example, React DOM. | ||
|
|
||
| React Native will fully support Hooks in its next stable release. | ||
|
|
||
| ### Do I need to rewrite all my class components? | ||
|
|
||
| No. There are [no plans](/docs/hooks-intro.html#gradual-adoption-strategy) to remove classes from React -- we all need to keep shipping products and can't afford rewrites. We recommend trying Hooks in new code. | ||
|
|
||
| ### What can I do with Hooks that I couldn't with classes? | ||
|
|
||
| Hooks offer a powerful and expressive new way to reuse functionality between components. ["Building Your Own Hooks"](/docs/hooks-custom.html) provides a glimpse of what's possible. [This article](https://medium.com/@dan_abramov/making-sense-of-react-hooks-fdbde8803889) by a React core team member dives deeper into the new capabilities unlocked by Hooks. | ||
|
|
||
| ### How much of my React knowledge stays relevant? | ||
|
|
||
| Hooks are a more direct way to use the React features you already know -- such as state, lifecycle, context, and refs. They don't fundamentally change how React works, and your knowledge of components, props, and top-down data flow is just as relevant. | ||
|
|
@@ -71,7 +90,7 @@ You can't use Hooks *inside* of a class component, but you can definitely mix cl | |
|
|
||
| Our goal is for Hooks to cover all use cases for classes as soon as possible. There are no Hook equivalents to the uncommon `getSnapshotBeforeUpdate` and `componentDidCatch` lifecycles yet, but we plan to add them soon. | ||
|
|
||
| It is a very early time for Hooks, so some integrations like DevTools support or Flow/TypeScript typings may not be ready yet. Some third-party libraries might also not be compatible with Hooks at the moment. | ||
| It is an early time for Hooks, and some third-party libraries might not be compatible with Hooks at the moment. | ||
|
|
||
| ### Do Hooks replace render props and higher-order components? | ||
|
|
||
|
|
@@ -85,7 +104,7 @@ In the future, new versions of these libraries might also export custom Hooks su | |
|
|
||
| ### Do Hooks work with static typing? | ||
|
|
||
| Hooks were designed with static typing in mind. Because they're functions, they are easier to type correctly than patterns like higher-order components. We have reached out both to Flow and TypeScript teams in advance, and they plan to include definitions for React Hooks in the future. | ||
| Hooks were designed with static typing in mind. Because they're functions, they are easier to type correctly than patterns like higher-order components. The latest Flow and TypeScript React definitions include support for React Hooks. | ||
|
|
||
| Importantly, custom Hooks give you the power to constrain React API if you'd like to type them more strictly in some way. React gives you the primitives, but you can combine them in different ways than what we provide out of the box. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ next: hooks-custom.html | |
| prev: hooks-effect.html | ||
| --- | ||
|
|
||
| *Hooks* are an upcoming feature that lets you use state and other React features without writing a class. They're currently in React v16.8.0-alpha.1. | ||
| *Hooks* let you use state and other React features without writing a class. | ||
|
|
||
| Hooks are JavaScript functions, but you need to follow two rules when using them. We provide a [linter plugin](https://www.npmjs.com/package/eslint-plugin-react-hooks) to enforce these rules automatically: | ||
|
|
||
|
|
@@ -28,7 +28,7 @@ By following this rule, you ensure that all stateful logic in a component is cle | |
| We released an ESLint plugin called [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks) that enforces these two rules. You can add this plugin to your project if you'd like to try it: | ||
|
|
||
| ```bash | ||
| npm install eslint-plugin-react-hooks@next | ||
| npm install eslint-plugin-react-hooks | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about a plugin that automatically provides hooks with the right arguments? Such as Check out a plugin of mine (still experimental): https://github.com/DAB0mB/babel-plugin-react-persist Would be nice to add it to the docs rather than people just searching around, or even worse, not using hooks when necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a part of facebook/react#14636 |
||
| ``` | ||
|
|
||
| ```js | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.