{"componentChunkName":"component---src-templates-blog-js","path":"/blog/2019/02/06/react-v16.8.0.html","result":{"data":{"markdownRemark":{"html":"<p>With React 16.8, <a href=\"/docs/hooks-intro.html\">React Hooks</a> are available in a stable release!</p>\n<h2 id=\"what-are-hooks\"><a href=\"#what-are-hooks\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What Are Hooks? </h2>\n<p>Hooks let you use state and other React features without writing a class. You can also <strong>build your own Hooks</strong> to share reusable stateful logic between components.</p>\n<p>If you’ve never heard of Hooks before, you might find these resources interesting:</p>\n<ul>\n<li><a href=\"/docs/hooks-intro.html\">Introducing Hooks</a> explains why we’re adding Hooks to React.</li>\n<li><a href=\"/docs/hooks-overview.html\">Hooks at a Glance</a> is a fast-paced overview of the built-in Hooks.</li>\n<li><a href=\"/docs/hooks-custom.html\">Building Your Own Hooks</a> demonstrates code reuse with custom Hooks.</li>\n<li><a href=\"https://medium.com/@dan_abramov/making-sense-of-react-hooks-fdbde8803889\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Making Sense of React Hooks</a> explores the new possibilities unlocked by Hooks.</li>\n<li><a href=\"https://usehooks.com/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">useHooks.com</a> showcases community-maintained Hooks recipes and demos.</li>\n</ul>\n<p><strong>You don’t have to learn Hooks right now.</strong> Hooks have no breaking changes, and we have no plans to remove classes from React. The <a href=\"/docs/hooks-faq.html\">Hooks FAQ</a> describes the gradual adoption strategy.</p>\n<h2 id=\"no-big-rewrites\"><a href=\"#no-big-rewrites\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>No Big Rewrites </h2>\n<p>We don’t recommend rewriting your existing applications to use Hooks overnight. Instead, try using Hooks in some of the new components, and let us know what you think. Code using Hooks will work <a href=\"/docs/hooks-intro.html#gradual-adoption-strategy\">side by side</a> with existing code using classes.</p>\n<h2 id=\"can-i-use-hooks-today\"><a href=\"#can-i-use-hooks-today\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Can I Use Hooks Today? </h2>\n<p>Yes! Starting with 16.8.0, React includes a stable implementation of React Hooks for:</p>\n<ul>\n<li>React DOM</li>\n<li>React DOM Server</li>\n<li>React Test Renderer</li>\n<li>React Shallow Renderer</li>\n</ul>\n<p>Note that <strong>to enable Hooks, all React packages need to be 16.8.0 or higher</strong>. Hooks won’t work if you forget to update, for example, React DOM.</p>\n<p><strong>React Native will support Hooks in the <a href=\"https://github.com/react-native-community/react-native-releases/issues/79#issuecomment-457735214\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">0.59 release</a>.</strong></p>\n<h2 id=\"tooling-support\"><a href=\"#tooling-support\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Tooling Support </h2>\n<p>React Hooks are now supported by React DevTools. They are also supported in the latest Flow and TypeScript definitions for React. We strongly recommend enabling a new <a href=\"https://www.npmjs.com/package/eslint-plugin-react-hooks\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">lint rule called <code class=\"gatsby-code-text\">eslint-plugin-react-hooks</code></a> to enforce best practices with Hooks. It will soon be included into Create React App by default.</p>\n<h2 id=\"whats-next\"><a href=\"#whats-next\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What’s Next </h2>\n<p>We described our plan for the next months in the recently published <a href=\"/blog/2018/11/27/react-16-roadmap.html\">React Roadmap</a>.</p>\n<p>Note that React Hooks don’t cover <em>all</em> use cases for classes yet but they’re <a href=\"/docs/hooks-faq.html#do-hooks-cover-all-use-cases-for-classes\">very close</a>. Currently, only <code class=\"gatsby-code-text\">getSnapshotBeforeUpdate()</code> and <code class=\"gatsby-code-text\">componentDidCatch()</code> methods don’t have equivalent Hooks APIs, and these lifecycles are relatively uncommon. If you want, you should be able to use Hooks in most of the new code you’re writing.</p>\n<p>Even while Hooks were in alpha, the React community created many interesting <a href=\"https://codesandbox.io/react-hooks\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">examples</a> and <a href=\"https://usehooks.com\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">recipes</a> using Hooks for animations, forms, subscriptions, integrating with other libraries, and so on. We’re excited about Hooks because they make code reuse easier, helping you write your components in a simpler way and make great user experiences. We can’t wait to see what you’ll create next!</p>\n<h2 id=\"testing-hooks\"><a href=\"#testing-hooks\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Testing Hooks </h2>\n<p>We have added a new API called <code class=\"gatsby-code-text\">ReactTestUtils.act()</code> in this release. It ensures that the behavior in your tests matches what happens in the browser more closely. We recommend to wrap any code rendering and triggering updates to your components into <code class=\"gatsby-code-text\">act()</code> calls. Testing libraries can also wrap their APIs with it (for example, <a href=\"https://testing-library.com/react\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><code class=\"gatsby-code-text\">react-testing-library</code></a>’s <code class=\"gatsby-code-text\">render</code> and <code class=\"gatsby-code-text\">fireEvent</code> utilities do this).</p>\n<p>For example, the counter example from <a href=\"/docs/hooks-effect.html\">this page</a> can be tested like this:</p>\n<div class=\"gatsby-highlight has-highlighted-lines\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ReactDOM <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom'</span><span class=\"token punctuation\">;</span>\n<span class=\"gatsby-highlight-code-line\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> act <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom/test-utils'</span><span class=\"token punctuation\">;</span></span><span class=\"token keyword\">import</span> Counter <span class=\"token keyword\">from</span> <span class=\"token string\">'./Counter'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> container<span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">beforeEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  container <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'div'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>container<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">afterEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">removeChild</span><span class=\"token punctuation\">(</span>container<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  container <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">it</span><span class=\"token punctuation\">(</span><span class=\"token string\">'can render and update a counter'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// Test first render and effect</span>\n<span class=\"gatsby-highlight-code-line\">  <span class=\"token function\">act</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">    ReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Counter</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">,</span> container<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></span>  <span class=\"token keyword\">const</span> button <span class=\"token operator\">=</span> container<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'button'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> label <span class=\"token operator\">=</span> container<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'p'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">expect</span><span class=\"token punctuation\">(</span>label<span class=\"token punctuation\">.</span>textContent<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toBe</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You clicked 0 times'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">expect</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toBe</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You clicked 0 times'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token comment\">// Test second render and effect</span>\n<span class=\"gatsby-highlight-code-line\">  <span class=\"token function\">act</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">    button<span class=\"token punctuation\">.</span><span class=\"token function\">dispatchEvent</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">MouseEvent</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>bubbles<span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></span>  <span class=\"token function\">expect</span><span class=\"token punctuation\">(</span>label<span class=\"token punctuation\">.</span>textContent<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toBe</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You clicked 1 times'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">expect</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toBe</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You clicked 1 times'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The calls to <code class=\"gatsby-code-text\">act()</code> will also flush the effects inside of them.</p>\n<p>If you need to test a custom Hook, you can do so by creating a component in your test, and using your Hook from it. Then you can test the component you wrote.</p>\n<p>To reduce the boilerplate, we recommend using <a href=\"https://testing-library.com/react\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><code class=\"gatsby-code-text\">react-testing-library</code></a> which is designed to encourage writing tests that use your components as the end users do.</p>\n<h2 id=\"thanks\"><a href=\"#thanks\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Thanks </h2>\n<p>We’d like to thank everybody who commented on the <a href=\"https://github.com/reactjs/rfcs/pull/68\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Hooks RFC</a> for sharing their feedback. We’ve read all of your comments and made some adjustments to the final API based on them.</p>\n<h2 id=\"installation\"><a href=\"#installation\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Installation </h2>\n<h3 id=\"react\"><a href=\"#react\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>React </h3>\n<p>React v16.8.0 is available on the npm registry.</p>\n<p>To install React 16 with Yarn, run:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"gatsby-code-bash\"><code class=\"gatsby-code-bash\"><span class=\"token function\">yarn</span> <span class=\"token function\">add</span> react@^16.8.0 react-dom@^16.8.0</code></pre></div>\n<p>To install React 16 with npm, run:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"gatsby-code-bash\"><code class=\"gatsby-code-bash\"><span class=\"token function\">npm</span> <span class=\"token function\">install</span> --save react@^16.8.0 react-dom@^16.8.0</code></pre></div>\n<p>We also provide UMD builds of React via a CDN:</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"gatsby-code-html\"><code class=\"gatsby-code-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span> <span class=\"token attr-name\">crossorigin</span> <span class=\"token attr-name\">src</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://unpkg.com/react@16/umd/react.production.min.js<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token script\"></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span> <span class=\"token attr-name\">crossorigin</span> <span class=\"token attr-name\">src</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://unpkg.com/react-dom@16/umd/react-dom.production.min.js<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token script\"></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<p>Refer to the documentation for <a href=\"/docs/installation.html\">detailed installation instructions</a>.</p>\n<h3 id=\"eslint-plugin-for-react-hooks\"><a href=\"#eslint-plugin-for-react-hooks\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>ESLint Plugin for React Hooks </h3>\n<blockquote>\n<p>Note</p>\n<p>As mentioned above, we strongly recommend using the <code class=\"gatsby-code-text\">eslint-plugin-react-hooks</code> lint rule.</p>\n<p>If you’re using Create React App, instead of manually configuring ESLint you can wait for the next version of <code class=\"gatsby-code-text\">react-scripts</code> which will come out shortly and will include this rule.</p>\n</blockquote>\n<p>Assuming you already have ESLint installed, run:</p>\n<div class=\"gatsby-highlight\" data-language=\"sh\"><pre class=\"gatsby-code-sh\"><code class=\"gatsby-code-sh\"># npm\nnpm install eslint-plugin-react-hooks --save-dev\n\n# yarn\nyarn add eslint-plugin-react-hooks --dev</code></pre></div>\n<p>Then add it to your ESLint configuration:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token punctuation\">{</span>\n  <span class=\"token string\">\"plugins\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token string\">\"react-hooks\"</span>\n  <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">\"rules\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token string\">\"react-hooks/rules-of-hooks\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"error\"</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2 id=\"changelog\"><a href=\"#changelog\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Changelog </h2>\n<h3 id=\"react-1\"><a href=\"#react-1\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>React </h3>\n<ul>\n<li>Add <a href=\"https://reactjs.org/docs/hooks-intro.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Hooks</a> — a way to use state and other React features without writing a class. (<a href=\"https://github.com/acdlite\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@acdlite</a> et al. in <a href=\"https://github.com/facebook/react/pull/13968\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#13968</a>)</li>\n<li>Improve the <code class=\"gatsby-code-text\">useReducer</code> Hook lazy initialization API. (<a href=\"https://github.com/acdlite\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@acdlite</a> in <a href=\"https://github.com/facebook/react/pull/14723\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14723</a>)</li>\n</ul>\n<h3 id=\"react-dom\"><a href=\"#react-dom\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>React DOM </h3>\n<ul>\n<li>Bail out of rendering on identical values for <code class=\"gatsby-code-text\">useState</code> and <code class=\"gatsby-code-text\">useReducer</code> Hooks. (<a href=\"https://github.com/acdlite\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@acdlite</a> in <a href=\"https://github.com/facebook/react/pull/14569\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14569</a>)</li>\n<li>Don’t compare the first argument passed to <code class=\"gatsby-code-text\">useEffect</code>/<code class=\"gatsby-code-text\">useMemo</code>/<code class=\"gatsby-code-text\">useCallback</code> Hooks. (<a href=\"https://github.com/acdlite\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@acdlite</a> in <a href=\"https://github.com/facebook/react/pull/14594\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14594</a>)</li>\n<li>Use <code class=\"gatsby-code-text\">Object.is</code> algorithm for comparing <code class=\"gatsby-code-text\">useState</code> and <code class=\"gatsby-code-text\">useReducer</code> values. (<a href=\"https://github.com/Jessidhia\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@Jessidhia</a> in <a href=\"https://github.com/facebook/react/pull/14752\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14752</a>)</li>\n<li>Support synchronous thenables passed to <code class=\"gatsby-code-text\">React.lazy()</code>. (<a href=\"https://github.com/gaearon\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@gaearon</a> in <a href=\"https://github.com/facebook/react/pull/14626\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14626</a>)</li>\n<li>Render components with Hooks twice in Strict Mode (DEV-only) to match class behavior. (<a href=\"https://github.com/gaearon\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@gaearon</a> in <a href=\"https://github.com/facebook/react/pull/14654\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14654</a>)</li>\n<li>Warn about mismatching Hook order in development. (<a href=\"https://github.com/threepointone\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@threepointone</a> in <a href=\"https://github.com/facebook/react/pull/14585\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14585</a> and <a href=\"https://github.com/acdlite\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@acdlite</a> in <a href=\"https://github.com/facebook/react/pull/14591\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14591</a>)</li>\n<li>Effect clean-up functions must return either <code class=\"gatsby-code-text\">undefined</code> or a function. All other values, including <code class=\"gatsby-code-text\">null</code>, are not allowed. <a href=\"https://github.com/acdlite\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@acdlite</a> in <a href=\"https://github.com/facebook/react/pull/14119\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14119</a></li>\n</ul>\n<h3 id=\"react-test-renderer\"><a href=\"#react-test-renderer\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>React Test Renderer </h3>\n<ul>\n<li>Support Hooks in the shallow renderer. (<a href=\"https://github.com/trueadm\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@trueadm</a> in <a href=\"https://github.com/facebook/react/pull/14567\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14567</a>)</li>\n<li>Fix wrong state in <code class=\"gatsby-code-text\">shouldComponentUpdate</code> in the presence of <code class=\"gatsby-code-text\">getDerivedStateFromProps</code> for Shallow Renderer. (<a href=\"https://github.com/chenesan\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@chenesan</a> in <a href=\"https://github.com/facebook/react/pull/14613\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14613</a>)</li>\n<li>Add <code class=\"gatsby-code-text\">ReactTestRenderer.act()</code> and <code class=\"gatsby-code-text\">ReactTestUtils.act()</code> for batching updates so that tests more closely match real behavior. (<a href=\"https://github.com/threepointone\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@threepointone</a> in <a href=\"https://github.com/facebook/react/pull/14744\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14744</a>)</li>\n</ul>\n<h3 id=\"eslint-plugin-react-hooks\"><a href=\"#eslint-plugin-react-hooks\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>ESLint Plugin: React Hooks </h3>\n<ul>\n<li>Initial <a href=\"https://www.npmjs.com/package/eslint-plugin-react-hooks\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">release</a>. (<a href=\"https://github.com/calebmer\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@calebmer</a> in <a href=\"https://github.com/facebook/react/pull/13968\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#13968</a>)</li>\n<li>Fix reporting after encountering a loop. (<a href=\"https://github.com/calebmer\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@calebmer</a> and <a href=\"https://github.com/Yurickh\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@Yurickh</a> in <a href=\"https://github.com/facebook/react/pull/14661\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14661</a>)</li>\n<li>Don’t consider throwing to be a rule violation. (<a href=\"https://github.com/sophiebits\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@sophiebits</a> in <a href=\"https://github.com/facebook/react/pull/14040\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14040</a>)</li>\n</ul>\n<h2 id=\"hooks-changelog-since-alpha-versions\"><a href=\"#hooks-changelog-since-alpha-versions\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Hooks Changelog Since Alpha Versions </h2>\n<p>The above changelog contains all notable changes since our last <strong>stable</strong> release (16.7.0). <a href=\"/docs/faq-versioning.html\">As with all our minor releases</a>, none of the changes break backwards compatibility.</p>\n<p>If you’re currently using Hooks from an alpha build of React, note that this release does contain some small breaking changes to Hooks. <strong>We don’t recommend depending on alphas in production code.</strong> We publish them so we can make changes in response to community feedback before the API is stable.</p>\n<p>Here are all breaking changes to Hooks that have been made since the first alpha release:</p>\n<ul>\n<li>Remove <code class=\"gatsby-code-text\">useMutationEffect</code>. (<a href=\"https://github.com/sophiebits\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@sophiebits</a> in <a href=\"https://github.com/facebook/react/pull/14336\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14336</a>)</li>\n<li>Rename <code class=\"gatsby-code-text\">useImperativeMethods</code> to <code class=\"gatsby-code-text\">useImperativeHandle</code>. (<a href=\"https://github.com/threepointone\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@threepointone</a> in <a href=\"https://github.com/facebook/react/pull/14565\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14565</a>)</li>\n<li>Bail out of rendering on identical values for <code class=\"gatsby-code-text\">useState</code> and <code class=\"gatsby-code-text\">useReducer</code> Hooks. (<a href=\"https://github.com/acdlite\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@acdlite</a> in <a href=\"https://github.com/facebook/react/pull/14569\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14569</a>)</li>\n<li>Don’t compare the first argument passed to <code class=\"gatsby-code-text\">useEffect</code>/<code class=\"gatsby-code-text\">useMemo</code>/<code class=\"gatsby-code-text\">useCallback</code> Hooks. (<a href=\"https://github.com/acdlite\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@acdlite</a> in <a href=\"https://github.com/facebook/react/pull/14594\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14594</a>)</li>\n<li>Use <code class=\"gatsby-code-text\">Object.is</code> algorithm for comparing <code class=\"gatsby-code-text\">useState</code> and <code class=\"gatsby-code-text\">useReducer</code> values. (<a href=\"https://github.com/Jessidhia\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@Jessidhia</a> in <a href=\"https://github.com/facebook/react/pull/14752\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14752</a>)</li>\n<li>Render components with Hooks twice in Strict Mode (DEV-only). (<a href=\"https://github.com/gaearon\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@gaearon</a> in <a href=\"https://github.com/facebook/react/pull/14654\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14654</a>)</li>\n<li>Improve the <code class=\"gatsby-code-text\">useReducer</code> Hook lazy initialization API. (<a href=\"https://github.com/acdlite\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">@acdlite</a> in <a href=\"https://github.com/facebook/react/pull/14723\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">#14723</a>)</li>\n</ul>","excerpt":"With React 16.8, React Hooks are available in a stable release! What Are Hooks?  Hooks let you use state and other React features without writing a class. You can also build your own Hooks to share reusable stateful logic between components. If you’ve never heard of Hooks before, you might find these resources interesting: Introducing Hooks explains why we’re adding Hooks to React. Hooks at a Glance is a fast-paced overview of the built-in Hooks. Building Your Own Hooks demonstrates code reuse…","frontmatter":{"title":"React v16.8: The One With Hooks","next":null,"prev":null,"author":[{"frontmatter":{"name":"Dan Abramov","url":"https://twitter.com/dan_abramov"}}]},"fields":{"date":"February 06, 2019","path":"content/blog/2019-02-06-react-v16.8.0.md","slug":"/blog/2019/02/06/react-v16.8.0.html"}},"allMarkdownRemark":{"edges":[{"node":{"frontmatter":{"title":"Introducing the New JSX Transform"},"fields":{"slug":"/blog/2020/09/22/introducing-the-new-jsx-transform.html"}}},{"node":{"frontmatter":{"title":"React v17.0 Release Candidate: No New Features"},"fields":{"slug":"/blog/2020/08/10/react-v17-rc.html"}}},{"node":{"frontmatter":{"title":"React v16.13.0"},"fields":{"slug":"/blog/2020/02/26/react-v16.13.0.html"}}},{"node":{"frontmatter":{"title":"Building Great User Experiences with Concurrent Mode and Suspense"},"fields":{"slug":"/blog/2019/11/06/building-great-user-experiences-with-concurrent-mode-and-suspense.html"}}},{"node":{"frontmatter":{"title":"Preparing for the Future with React Prereleases"},"fields":{"slug":"/blog/2019/10/22/react-release-channels.html"}}},{"node":{"frontmatter":{"title":"Introducing the New React DevTools"},"fields":{"slug":"/blog/2019/08/15/new-react-devtools.html"}}},{"node":{"frontmatter":{"title":"React v16.9.0 and the Roadmap Update"},"fields":{"slug":"/blog/2019/08/08/react-v16.9.0.html"}}},{"node":{"frontmatter":{"title":"Is React Translated Yet? ¡Sí! Sim! はい！"},"fields":{"slug":"/blog/2019/02/23/is-react-translated-yet.html"}}},{"node":{"frontmatter":{"title":"React v16.8: The One With Hooks"},"fields":{"slug":"/blog/2019/02/06/react-v16.8.0.html"}}},{"node":{"frontmatter":{"title":"React v16.7: No, This Is Not the One With Hooks"},"fields":{"slug":"/blog/2018/12/19/react-v-16-7.html"}}}]}},"pageContext":{"slug":"/blog/2019/02/06/react-v16.8.0.html"}},"staticQueryHashes":[]}