<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[React]]></title><description><![CDATA[A JavaScript library for building user interfaces]]></description><link>https://reactjs.org</link><generator>RSS for Node</generator><lastBuildDate>Wed, 24 Jul 2019 04:28:55 GMT</lastBuildDate><item><title><![CDATA[Is React Translated Yet? ¡Sí! Sim! はい！]]></title><description><![CDATA[<p>We’re excited to announce an ongoing effort to maintain official translations of the React documentation website into different languages. Thanks to the dedicated efforts of React community members from around the world, React is now being translated into <em>over 30</em> languages! You can find them on the new <a href="/languages">Languages</a> page.</p>
<p>In addition, the following three languages have completed translating most of the React Docs! 🎉</p>
<ul>
<li><strong>Spanish: <a href="https://es.reactjs.org" target="_blank" rel="nofollow noopener noreferrer">es.reactjs.org</a></strong></li>
<li><strong>Japanese: <a href="https://ja.reactjs.org" target="_blank" rel="nofollow noopener noreferrer">ja.reactjs.org</a></strong></li>
<li><strong>Brazilian Portuguese: <a href="https://pt-br.reactjs.org" target="_blank" rel="nofollow noopener noreferrer">pt-br.reactjs.org</a></strong></li>
</ul>
<p>Special congratulations to <a href="https://github.com/alejandronanez" target="_blank" rel="nofollow noopener noreferrer">Alejandro Ñáñez Ortiz</a>, <a href="https://github.com/carburo" target="_blank" rel="nofollow noopener noreferrer">Rainer Martínez Fraga</a>, <a href="https://github.com/dmorales" target="_blank" rel="nofollow noopener noreferrer">David Morales</a>, <a href="https://github.com/Darking360" target="_blank" rel="nofollow noopener noreferrer">Miguel Alejandro Bolivar Portilla</a>, and all the contributors to the Spanish translation for being the first to <em>completely</em> translate the core pages of the docs!</p>
<h2 id="why-localization-matters"><a href="#why-localization-matters" aria-hidden="true" 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>Why Localization Matters </h2>
<p>React already has many meetups and conferences around the world, but many programmers don’t use English as their primary language. We’d love to support local communities who use React by making our documentation available in most popular languages.</p>
<p>In the past, React community members have created unofficial translations for <a href="https://github.com/discountry/react" target="_blank" rel="nofollow noopener noreferrer">Chinese</a>, <a href="https://wiki.hsoub.com/React" target="_blank" rel="nofollow noopener noreferrer">Arabic</a>, and <a href="https://github.com/reactjs/ko.reactjs.org/issues/4" target="_blank" rel="nofollow noopener noreferrer">Korean</a>; by making an official channel for these translated docs we’re hoping to make them easier to find and help make sure that non-English-speaking users of React aren’t left behind.</p>
<h2 id="contributing"><a href="#contributing" aria-hidden="true" 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>Contributing </h2>
<p>If you would like to help out on a current translation, check out the <a href="/languages">Languages</a> page and click on the “Contribute” link for your language.</p>
<p>Can’t find your language? If you’d like to maintain your language’s translation fork, follow the instructions in the <a href="https://github.com/reactjs/reactjs.org-translation#starting-a-new-translation" target="_blank" rel="nofollow noopener noreferrer">translation repo</a>!</p>
<h2 id="backstory"><a href="#backstory" aria-hidden="true" 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>Backstory </h2>
<p>Hi everyone! I’m <a href="https://twitter.com/tesseralis" target="_blank" rel="nofollow noopener noreferrer">Nat</a>! You may know me as the <a href="https://www.youtube.com/watch?v=Ew-UzGC8RqQ" target="_blank" rel="nofollow noopener noreferrer">polyhedra lady</a>. For the past few weeks, I’ve been helping the React team coordinate their translation effort. Here’s how I did it.</p>
<p>Our original approach for translations was to use a SaaS platform that allows users to submit translations. There was already a <a href="https://github.com/reactjs/reactjs.org/pull/873" target="_blank" rel="nofollow noopener noreferrer">pull request</a> to integrate it and my original responsibility was to finish that integration. However, we had concerns about the feasibility of that integration and the current quality of translations on the platform. Our primary concern was ensuring that translations kept up to date with the main repo and didn’t become “stale”.</p>
<p><a href="https://twitter.com/dan_abramov" target="_blank" rel="nofollow noopener noreferrer">Dan</a> encouraged me to look for alternate solutions, and we stumbled across how <a href="https://vuejs.org" target="_blank" rel="nofollow noopener noreferrer">Vue</a> maintained its translations — through different forks of the main repo on GitHub. In particular, the <a href="https://jp.vuejs.org" target="_blank" rel="nofollow noopener noreferrer">Japanese translation</a> used a bot to periodically check for changes in the English repo and submits pull requests whenever there is a change.</p>
<p>This approach appealed to us for several reasons:</p>
<ul>
<li>It was less code integration to get off the ground.</li>
<li>It encouraged active maintainers for each repo to ensure quality.</li>
<li>Contributors already understand GitHub as a platform and are motivated to contribute directly to the React organization.</li>
</ul>
<p>We started off with an initial trial period of three languages: Spanish, Japanese, and Simplified Chinese. This allowed us to work out any kinks in our process and make sure future translations are set up for success. I wanted to give the translation teams freedom to choose whatever tools they felt comfortable with. The only requirement is a <a href="https://github.com/reactjs/reactjs.org-translation/blob/master/PROGRESS.template.md" target="_blank" rel="nofollow noopener noreferrer">checklist</a> that outlines the order of importance for translating pages. </p>
<p>After the trial period, we were ready to accept more languages. I created <a href="https://github.com/reactjs/reactjs.org-translation/blob/master/scripts/create.js" target="_blank" rel="nofollow noopener noreferrer">a script</a> to automate the creation of the new language repo, and a site, <a href="https://isreacttranslatedyet.com" target="_blank" rel="nofollow noopener noreferrer">Is React Translated Yet?</a>, to track progress on the different translations. We started <em>10</em> new translations on our first day alone!</p>
<p>Because of the automation, the rest of the maintenance went mostly smoothly. We eventually created a <a href="https://rt-slack-invite.herokuapp.com" target="_blank" rel="nofollow noopener noreferrer">Slack channel</a> to make it easier for translators to share information, and I released a guide solidifying the <a href="https://github.com/reactjs/reactjs.org-translation/blob/master/maintainer-guide.md" target="_blank" rel="nofollow noopener noreferrer">responsibilities of maintainers</a>. Allowing translators to talk with each other was a great boon — for example, the Arabic, Persian, and Hebrew translations were able to talk to each other in order to get <a href="https://en.wikipedia.org/wiki/Right-to-left" target="_blank" rel="nofollow noopener noreferrer">right-to-left text</a> working!</p>
<h2 id="the-bot"><a href="#the-bot" aria-hidden="true" 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>The Bot </h2>
<p>The most challenging part was getting the bot to sync changes from the English version of the site. Initially we were using the <a href="https://github.com/vuejs-jp/che-tsumi" target="_blank" rel="nofollow noopener noreferrer">che-tsumi</a> bot created by the Japanese Vue translation team, but we soon decided to build our own bot to suit our needs. In particular, the che-tsumi bot works by <a href="https://git-scm.com/docs/git-cherry-pick" target="_blank" rel="nofollow noopener noreferrer">cherry picking</a> new commits. This ended up causing a cavalade of new issues that were interconnected, especially when <a href="/blog/2019/02/06/react-v16.8.0.html">Hooks were released</a>.</p>
<p>In the end, we decided that instead of cherry picking each commit, it made more sense to merge all new commits and create a pull request around once a day. Conflicts are merged as-is and listed in the <a href="https://github.com/reactjs/pt-BR.reactjs.org/pull/114" target="_blank" rel="nofollow noopener noreferrer">pull request</a>, leaving a checklist for maintainers to fix.</p>
<p>Creating the <a href="https://github.com/reactjs/reactjs.org-translation/blob/master/scripts/sync.js" target="_blank" rel="nofollow noopener noreferrer">sync script</a> was easy enough: it downloads the translated repo, adds the original as a remote, pulls from it, merges the conflicts, and creates a pull request.</p>
<p>The problem was finding a place for the bot to run. I’m a frontend developer for a reason — Heroku and its ilk are alien to me and <em>endlessly</em> frustrating. In fact, until this past Tuesday, I was running the script by hand on my local machine!</p>
<p>The biggest challenge was space. Each fork of the repo is around 100MB — which takes minutes to clone on my local machine. We have <em>32</em> forks, and the free tiers or most deployment platforms I checked limited you to 512MB of storage. </p>
<p>After lots of notepad calculations, I found a solution: delete each repo once we’ve finished the script and limit the concurrency of <code class="gatsby-code-text">sync</code> scripts that run at once to be within the storage requirements. Luckily, Heroku dynos have a much faster Internet connection and are able to clone even the React repo quickly.</p>
<p>There were other smaller issues that I ran into. I tried using the <a href="https://elements.heroku.com/addons/scheduler" target="_blank" rel="nofollow noopener noreferrer">Heroku Scheduler</a> add-on so I didn’t have to write any actual <code class="gatsby-code-text">watch</code> code, but it end up running too inconsistently, and I <a href="https://twitter.com/tesseralis/status/1097387938088796160" target="_blank" rel="nofollow noopener noreferrer">had an existential meltdown on Twitter</a> when I couldn’t figure out how to send commits from the Heroku dyno. But in the end, this frontend engineer was able to get the bot working!</p>
<p>There are, as always, improvements I want to make to the bot. Right now it doesn’t check whether there is an outstanding pull request before pushing another one. It’s still hard to tell the exact change that happened in the original source, and it’s possible to miss out on a needed translation change. But I trust the maintainers we’ve chosen to work through these issues, and the bot is <a href="https://github.com/reactjs/reactjs.org-translation" target="_blank" rel="nofollow noopener noreferrer">open source</a> if anyone wants to help me make these improvements!</p>
<h2 id="thanks"><a href="#thanks" aria-hidden="true" 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>
<p>Finally, I would like to extend my gratitude to the following people and groups:</p>
<ul>
<li>All the translation maintainers and contributors who are helping translate React to more than thirty languages.</li>
<li>The <a href="https://github.com/vuejs-jp" target="_blank" rel="nofollow noopener noreferrer">Vue.js Japan User Group</a> for initiating the idea of having bot-managed translations, and especially <a href="https://github.com/potato4d" target="_blank" rel="nofollow noopener noreferrer">Hanatani Takuma</a> for helping us understand their approach and helping maintain the Japanese translation.</li>
<li><a href="https://github.com/smikitky" target="_blank" rel="nofollow noopener noreferrer">Soichiro Miki</a> for many <a href="https://github.com/reactjs/reactjs.org/pull/1636" target="_blank" rel="nofollow noopener noreferrer">contributions</a> and thoughtful comments on the overall translation process, as well as for maintaining the Japanese translation.</li>
<li><a href="https://github.com/ericnakagawa" target="_blank" rel="nofollow noopener noreferrer">Eric Nakagawa</a> for managing our previous translation process.</li>
<li><a href="https://github.com/bvaughn" target="_blank" rel="nofollow noopener noreferrer">Brian Vaughn</a> for setting up the <a href="/languages">languages page</a> and managing all the subdomains.</li>
</ul>
<p> And finally, thank you to <a href="https://twitter.com/dan_abramov" target="_blank" rel="nofollow noopener noreferrer">Dan Abramov</a> for giving me this opportunity and being a great mentor along the way.</p>]]></description><link>https://reactjs.org/blog/2019/02/23/is-react-translated-yet.html</link><guid isPermaLink="false">https://reactjs.org/blog/2019/02/23/is-react-translated-yet.html</guid><pubDate>Sat, 23 Feb 2019 00:00:00 GMT</pubDate></item><item><title><![CDATA[React v16.8: The One With Hooks]]></title><description><![CDATA[<p>With React 16.8, <a href="/docs/hooks-intro.html">React Hooks</a> are available in a stable release!</p>
<h2 id="what-are-hooks"><a href="#what-are-hooks" aria-hidden="true" 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>
<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>
<p>If you’ve never heard of Hooks before, you might find these resources interesting:</p>
<ul>
<li><a href="/docs/hooks-intro.html">Introducing Hooks</a> explains why we’re adding Hooks to React.</li>
<li><a href="/docs/hooks-overview.html">Hooks at a Glance</a> is a fast-paced overview of the built-in Hooks.</li>
<li><a href="/docs/hooks-custom.html">Building Your Own Hooks</a> demonstrates code reuse with custom Hooks.</li>
<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>
<li><a href="https://usehooks.com/" target="_blank" rel="nofollow noopener noreferrer">useHooks.com</a> showcases community-maintained Hooks recipes and demos.</li>
</ul>
<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>
<h2 id="no-big-rewrites"><a href="#no-big-rewrites" aria-hidden="true" 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>
<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>
<h2 id="can-i-use-hooks-today"><a href="#can-i-use-hooks-today" aria-hidden="true" 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>
<p>Yes! Starting with 16.8.0, React includes a stable implementation of React Hooks for:</p>
<ul>
<li>React DOM</li>
<li>React DOM Server</li>
<li>React Test Renderer</li>
<li>React Shallow Renderer</li>
</ul>
<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>
<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>
<h2 id="tooling-support"><a href="#tooling-support" aria-hidden="true" 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>
<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>
<h2 id="whats-next"><a href="#whats-next" aria-hidden="true" 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>
<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>
<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>
<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>
<h2 id="testing-hooks"><a href="#testing-hooks" aria-hidden="true" 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>
<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://github.com/kentcdodds/react-testing-library" 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>
<p>For example, the counter example from <a href="/docs/hooks-effect.html">this page</a> can be tested like this:</p>
<div class="gatsby-highlight" 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>
<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>
<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>

<span class="token keyword">let</span> container<span class="token punctuation">;</span>

<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>
  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>
  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>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<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>
  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>
  container <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<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>
  <span class="token comment">// Test first render and effect</span>
<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>Counter</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>
  <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>
  <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>
  <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>

  <span class="token comment">// Test second render and effect</span>
<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 punctuation">:</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>
  <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>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>The calls to <code class="gatsby-code-text">act()</code> will also flush the effects inside of them.</p>
<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>
<p>To reduce the boilerplate, we recommend using <a href="https://git.io/react-testing-library" 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>
<h2 id="thanks"><a href="#thanks" aria-hidden="true" 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>
<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>
<h2 id="installation"><a href="#installation" aria-hidden="true" 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>
<h3 id="react"><a href="#react" aria-hidden="true" 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>
<p>React v16.8.0 is available on the npm registry.</p>
<p>To install React 16 with Yarn, run:</p>
<div class="gatsby-highlight" data-language="bash"><pre class="gatsby-code-bash"><code class="gatsby-code-bash">yarn add react@^16.8.0 react-dom@^16.8.0</code></pre></div>
<p>To install React 16 with npm, run:</p>
<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>
<p>We also provide UMD builds of React via a CDN:</p>
<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">=</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 language-javascript"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">></span></span>
<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">=</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 language-javascript"></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>
<p>Refer to the documentation for <a href="/docs/installation.html">detailed installation instructions</a>.</p>
<h3 id="eslint-plugin-for-react-hooks"><a href="#eslint-plugin-for-react-hooks" aria-hidden="true" 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>
<blockquote>
<p>Note</p>
<p>As mentioned above, we strongly recommend using the <code class="gatsby-code-text">eslint-plugin-react-hooks</code> lint rule.</p>
<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>
</blockquote>
<p>Assuming you already have ESLint installed, run:</p>
<div class="gatsby-highlight" data-language="sh"><pre class="gatsby-code-sh"><code class="gatsby-code-sh"># npm
npm install eslint-plugin-react-hooks --save-dev

# yarn
yarn add eslint-plugin-react-hooks --dev</code></pre></div>
<p>Then add it to your ESLint configuration:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token punctuation">{</span>
  <span class="token string">"plugins"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
    <span class="token comment">// ...</span>
    <span class="token string">"react-hooks"</span>
  <span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token string">"rules"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token comment">// ...</span>
    <span class="token string">"react-hooks/rules-of-hooks"</span><span class="token punctuation">:</span> <span class="token string">"error"</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<h2 id="changelog"><a href="#changelog" aria-hidden="true" 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>
<h3 id="react-1"><a href="#react-1" aria-hidden="true" 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>
<ul>
<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>
<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>
</ul>
<h3 id="react-dom"><a href="#react-dom" aria-hidden="true" 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>
<ul>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
</ul>
<h3 id="react-test-renderer"><a href="#react-test-renderer" aria-hidden="true" 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>
<ul>
<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>
<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>
<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>
</ul>
<h3 id="eslint-plugin-react-hooks"><a href="#eslint-plugin-react-hooks" aria-hidden="true" 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>
<ul>
<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>
<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>
<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>
</ul>
<h2 id="hooks-changelog-since-alpha-versions"><a href="#hooks-changelog-since-alpha-versions" aria-hidden="true" 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>
<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>
<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>
<p>Here are all breaking changes to Hooks that have been made since the first alpha release:</p>
<ul>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
</ul>]]></description><link>https://reactjs.org/blog/2019/02/06/react-v16.8.0.html</link><guid isPermaLink="false">https://reactjs.org/blog/2019/02/06/react-v16.8.0.html</guid><pubDate>Wed, 06 Feb 2019 00:00:00 GMT</pubDate></item><item><title><![CDATA[React v16.7: No, This Is Not the One With Hooks]]></title><description><![CDATA[<p>Our latest release includes an important performance bugfix for <code class="gatsby-code-text">React.lazy</code>. Although there are no API changes, we’re releasing it as a minor instead of a patch.</p>
<h2 id="why-is-this-bugfix-a-minor-instead-of-a-patch"><a href="#why-is-this-bugfix-a-minor-instead-of-a-patch" aria-hidden="true" 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>Why Is This Bugfix a Minor Instead of a Patch? </h2>
<p>React follows <a href="/docs/faq-versioning.html">semantic versioning</a>. Typically, this means that we use patch versions for bugfixes, and minors for new (non-breaking) features. However, we reserve the option to release minor versions even if they do not include new features. The motivation is to reserve patches for changes that have a very low chance of breaking. Patches are the most important type of release because they sometimes contain critical bugfixes. That means patch releases have a higher bar for reliability. It’s unacceptable for a patch to introduce additional bugs, because if people come to distrust patches, it compromises our ability to fix critical bugs when they arise — for example, to fix a security vulnerability.</p>
<p>We never intend to ship bugs. React has a hard-earned reputation for stability, and we intend to keep it that way. We thoroughly test every version of React before releasing. This includes unit tests, generative (fuzzy) tests, integration tests, and internal dogfooding across tens of thousands of components. However, sometimes we make mistakes. That’s why, going forward, our policy will be that if a release contains non-trivial changes, we will bump the minor version, even if the external behavior is the same. We’ll also bump the minor when changing <code class="gatsby-code-text">unstable_</code>-prefixed APIs.</p>
<h2 id="can-i-use-hooks-yet"><a href="#can-i-use-hooks-yet" aria-hidden="true" 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 Yet? </h2>
<p>Not yet, but soon!</p>
<p>At React Conf, we said that 16.7 would be the first release to include Hooks. This was a mistake. We shouldn’t have attached a specific version number to an unreleased feature. We’ll avoid this in the future.</p>
<p>Although 16.7 does not include Hooks, please do not infer anything about the timeline of the Hooks launch. Our plans for Hooks are unchanged:</p>
<ul>
<li>The <a href="https://github.com/reactjs/rfcs/pull/68" target="_blank" rel="nofollow noopener noreferrer">Hooks proposal</a> was accepted (<a href="https://github.com/reactjs/rfcs/pull/68#issuecomment-439314884" target="_blank" rel="nofollow noopener noreferrer">with minor planned changes in response to feedback</a>).</li>
<li>The <a href="https://github.com/facebook/react/commit/7bee9fbdd49aa5b9365a94b0ddf6db04bc1bf51c" target="_blank" rel="nofollow noopener noreferrer">implementation</a> was merged into the React repo (behind a feature flag).</li>
<li>We’re currently in the testing phase, and you can expect a public release within a few months.</li>
</ul>
<p>We’ve heard from many people who want to start using Hooks in their apps. We also can’t wait to ship them! But because Hooks changes how we write React components, we are taking extra time to get the details right. We appreciate your patience as we prepare this exciting new feature for widespread, ahem, <em>use</em>.</p>
<p>Learn more about <a href="/blog/2018/11/27/react-16-roadmap.html">our roadmap</a> in our previous post.</p>
<h2 id="installation"><a href="#installation" aria-hidden="true" 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>
<p>React v16.7.0 is available on the npm registry.</p>
<p>To install React 16 with Yarn, run:</p>
<div class="gatsby-highlight" data-language="bash"><pre class="gatsby-code-bash"><code class="gatsby-code-bash">yarn add react@^16.7.0 react-dom@^16.7.0</code></pre></div>
<p>To install React 16 with npm, run:</p>
<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.7.0 react-dom@^16.7.0</code></pre></div>
<p>We also provide UMD builds of React via a CDN:</p>
<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">=</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 language-javascript"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">></span></span>
<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">=</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 language-javascript"></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>
<p>Refer to the documentation for <a href="/docs/installation.html">detailed installation instructions</a>.</p>
<h2 id="changelog"><a href="#changelog" aria-hidden="true" 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>
<h3 id="react-dom"><a href="#react-dom" aria-hidden="true" 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>
<ul>
<li>Fix performance of <code class="gatsby-code-text">React.lazy</code> for large numbers of lazily-loaded components. (<a href="http://github.com/acdlite" target="_blank" rel="nofollow noopener noreferrer">@acdlite</a> in <a href="https://github.com/facebook/react/pull/14429" target="_blank" rel="nofollow noopener noreferrer">#14429</a>)</li>
<li>Clear fields on unmount to avoid memory leaks. (<a href="http://github.com/trueadm" target="_blank" rel="nofollow noopener noreferrer">@trueadm</a> in <a href="https://github.com/facebook/react/pull/14276" target="_blank" rel="nofollow noopener noreferrer">#14276</a>)</li>
<li>Fix bug with SSR and context when mixing <code class="gatsby-code-text">react-dom/server@16.6</code> and <code class="gatsby-code-text">react@&lt;16.6</code>. (<a href="http://github.com/gaearon" target="_blank" rel="nofollow noopener noreferrer">@gaearon</a> in <a href="https://github.com/facebook/react/pull/14291" target="_blank" rel="nofollow noopener noreferrer">#14291</a>)</li>
<li>Fix a performance regression in profiling mode. (<a href="http://github.com/bvaughn" target="_blank" rel="nofollow noopener noreferrer">@bvaughn</a> in <a href="https://github.com/facebook/react/pull/14383" target="_blank" rel="nofollow noopener noreferrer">#14383</a>)</li>
</ul>
<h3 id="scheduler-experimental"><a href="#scheduler-experimental" aria-hidden="true" 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>Scheduler (Experimental) </h3>
<ul>
<li>Post to MessageChannel instead of window. (<a href="http://github.com/acdlite" target="_blank" rel="nofollow noopener noreferrer">@acdlite</a> in <a href="https://github.com/facebook/react/pull/14234" target="_blank" rel="nofollow noopener noreferrer">#14234</a>)</li>
<li>Reduce serialization overhead. (<a href="http://github.com/developit" target="_blank" rel="nofollow noopener noreferrer">@developit</a> in <a href="https://github.com/facebook/react/pull/14249" target="_blank" rel="nofollow noopener noreferrer">#14249</a>)</li>
<li>Fix fallback to <code class="gatsby-code-text">setTimeout</code> in testing environments. (<a href="http://github.com/bvaughn" target="_blank" rel="nofollow noopener noreferrer">@bvaughn</a> in <a href="https://github.com/facebook/react/pull/14358" target="_blank" rel="nofollow noopener noreferrer">#14358</a>)</li>
<li>Add methods for debugging. (<a href="http://github.com/mrkev" target="_blank" rel="nofollow noopener noreferrer">@mrkev</a> in <a href="https://github.com/facebook/react/pull/14053" target="_blank" rel="nofollow noopener noreferrer">#14053</a>)</li>
</ul>]]></description><link>https://reactjs.org/blog/2018/12/19/react-v-16-7.html</link><guid isPermaLink="false">https://reactjs.org/blog/2018/12/19/react-v-16-7.html</guid><pubDate>Wed, 19 Dec 2018 00:00:00 GMT</pubDate></item><item><title><![CDATA[React 16.x Roadmap]]></title><description><![CDATA[<p>You might have heard about features like “Hooks”, “Suspense”, and “Concurrent Rendering” in the previous blog posts and talks. In this post, we’ll look at how they fit together and the expected timeline for their availability in a stable release of React.</p>
<h2 id="tldr"><a href="#tldr" aria-hidden="true" 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>tl;dr </h2>
<p>We plan to split the rollout of new React features into the following milestones:</p>
<ul>
<li>React 16.6 with <a href="#react-166-shipped-the-one-with-suspense-for-code-splitting">Suspense for Code Splitting</a> (<em>already shipped</em>)</li>
<li>A minor 16.x release with <a href="#react-16x-q1-2019-the-one-with-hooks">React Hooks</a> (~Q1 2019)</li>
<li>A minor 16.x release with <a href="#react-16x-q2-2019-the-one-with-concurrent-mode">Concurrent Mode</a> (~Q2 2019)</li>
<li>A minor 16.x release with <a href="#react-16x-mid-2019-the-one-with-suspense-for-data-fetching">Suspense for Data Fetching</a> (~mid 2019)</li>
</ul>
<p><em>(The original version of this post used exact version numbers. We edited it to reflect that there might need to be a few other minor releases in the middle between these ones.)</em></p>
<p>These are estimates, and the details may change as we’re further along. There’s at least two more projects we plan to complete in 2019. They require more exploration and aren’t tied to a particular release yet:</p>
<ul>
<li><a href="#modernizing-react-dom">Modernizing React DOM</a></li>
<li><a href="#suspense-for-server-rendering">Suspense for Server Rendering</a></li>
</ul>
<p>We expect to get more clarity on their timeline in the coming months.</p>
<blockquote>
<p>Note</p>
<p>This post is just a roadmap — there is nothing in it that requires your immediate attention. When each of these features are released, we’ll publish a full blog post announcing them.</p>
</blockquote>
<h2 id="release-timeline"><a href="#release-timeline" aria-hidden="true" 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>Release Timeline </h2>
<p>We have a single vision for how all of these features fit together, but we’re releasing each part as soon as it is ready so that you can test and start using them sooner. The API design doesn’t always make sense when looking at one piece in isolation; this post lays out the major parts of our plan to help you see the whole picture. (See our <a href="/docs/faq-versioning.html">versioning policy</a> to learn more about our commitment to stability.)</p>
<p>The gradual release strategy helps us refine the APIs, but the transitional period when some things aren’t ready can be confusing. Let’s look at what these different features mean for your app, how they relate to each other, and when you can expect to start learning and using them.</p>
<h3 id="react-166-shipped-the-one-with-suspense-for-code-splitting"><a href="#react-166-shipped-the-one-with-suspense-for-code-splitting" aria-hidden="true" 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><a href="/blog/2018/10/23/react-v-16-6.html">React 16.6</a> (shipped): The One with Suspense for Code Splitting </h3>
<p><em>Suspense</em> refers to React’s new ability to “suspend” rendering while components are waiting for something, and display a loading indicator. In React 16.6, Suspense supports only one use case: lazy loading components with <code class="gatsby-code-text">React.lazy()</code> and <code class="gatsby-code-text">&lt;React.Suspense&gt;</code>.</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token comment">// This component is loaded dynamically</span>
<span class="token keyword">const</span> OtherComponent <span class="token operator">=</span> React<span class="token punctuation">.</span><span class="token function">lazy</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'./OtherComponent'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">function</span> <span class="token function">MyComponent</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>React.Suspense</span> <span class="token attr-name">fallback</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Spinner</span> <span class="token punctuation">/></span></span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span><span class="token plain-text">
      </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">></span></span><span class="token plain-text">
        </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>OtherComponent</span> <span class="token punctuation">/></span></span><span class="token plain-text">
      </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span><span class="token plain-text">
    </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>React.Suspense</span><span class="token punctuation">></span></span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Code splitting with <code class="gatsby-code-text">React.lazy()</code> with <code class="gatsby-code-text">&lt;React.Suspense&gt;</code> is documented <a href="/docs/code-splitting.html#reactlazy">in the Code Splitting guide</a>. You can find another practical explanation in <a href="https://medium.com/@pomber/lazy-loading-and-preloading-components-in-react-16-6-804de091c82d" target="_blank" rel="nofollow noopener noreferrer">this article</a>.</p>
<p>We have been using Suspense for code splitting at Facebook since July, and expect it to be stable. There’s been a few regressions in the initial public release in 16.6.0, but they were fixed in 16.6.3.</p>
<p>Code splitting is just the first step for Suspense. Our longer term vision for Suspense involves letting it handle data fetching too (and integrate with libraries like Apollo). In addition to a convenient programming model, Suspense also provides better user experience in Concurrent Mode. You’ll find information about these topics further below.</p>
<p><strong>Status in React DOM:</strong> Available since React 16.6.0.</p>
<p><strong>Status in React DOM Server:</strong> Suspense is not available in the server renderer yet. This isn’t for the lack of attention. We’ve started work on a new asynchronous server renderer that will support Suspense, but it’s a large project and will take a good chunk of 2019 to complete.</p>
<p><strong>Status in React Native:</strong> Bundle splitting isn’t very useful in React Native, but there’s nothing technically preventing <code class="gatsby-code-text">React.lazy()</code> and <code class="gatsby-code-text">&lt;Suspense&gt;</code> from working when given a Promise to a module.</p>
<p><strong>Recommendation:</strong> If you only do client rendering, we recommend widely adopting <code class="gatsby-code-text">React.lazy()</code> and <code class="gatsby-code-text">&lt;React.Suspense&gt;</code> for code splitting React components. If you do server rendering, you’ll have to wait with adoption until the new server renderer is ready.</p>
<h3 id="react-16x-q1-2019-the-one-with-hooks"><a href="#react-16x-q1-2019-the-one-with-hooks" aria-hidden="true" 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 16.x (~Q1 2019): The One with Hooks </h3>
<p><em>Hooks</em> let you use features like state and lifecycle from function components. They also let you reuse stateful logic between components without introducing extra nesting in your tree.</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">function</span> <span class="token function">Example</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">// Declare a new state variable, which we'll call "count"</span>
  <span class="token keyword">const</span> <span class="token punctuation">[</span>count<span class="token punctuation">,</span> setCount<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">useState</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">return</span> <span class="token punctuation">(</span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">></span></span><span class="token plain-text">
     </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">></span></span><span class="token plain-text">You clicked </span><span class="token punctuation">{</span>count<span class="token punctuation">}</span><span class="token plain-text"> times</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">></span></span><span class="token plain-text">
     </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token function">setCount</span><span class="token punctuation">(</span>count <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span><span class="token plain-text">
       Click me
     </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">></span></span><span class="token plain-text">
   </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>
 <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>Hooks <a href="/docs/hooks-intro.html">introduction</a> and <a href="/docs/hooks-overview.html">overview</a> are good places to start. Watch <a href="https://www.youtube.com/watch?v=V-QO-KO90iQ" target="_blank" rel="nofollow noopener noreferrer">these talks</a> for a video introduction and a deep dive. The <a href="/docs/hooks-faq.html">FAQ</a> should answer most of your further questions. To learn more about the motivation behind Hooks, you can read <a href="https://medium.com/@dan_abramov/making-sense-of-react-hooks-fdbde8803889" target="_blank" rel="nofollow noopener noreferrer">this article</a>. Some of the rationale for the API design of Hooks is explained in <a href="https://github.com/reactjs/rfcs/pull/68#issuecomment-439314884" target="_blank" rel="nofollow noopener noreferrer">this RFC thread reply</a>.</p>
<p>We have been dogfooding Hooks at Facebook since September. We don’t expect major bugs in the implementation. Hooks are only available in the 16.7 alpha versions of React. Some of their API is expected to change in the final version (see the end of <a href="https://github.com/reactjs/rfcs/pull/68#issuecomment-439314884" target="_blank" rel="nofollow noopener noreferrer">this comment</a> for details). It is possible that the minor release with Hooks might not be React 16.7.</p>
<p>Hooks represent our vision for the future of React. They solve both problems that React users experience directly (“wrapper hell” of render props and higher-order components, duplication of logic in lifecycle methods), and the issues we’ve encountered optimizing React at scale (such as difficulties in inlining components with a compiler). Hooks don’t deprecate classes. However, if Hooks are successful, it is possible that in a future <em>major</em> release class support might move to a separate package, reducing the default bundle size of React.</p>
<p><strong>Status in React DOM:</strong> The first version of <code class="gatsby-code-text">react</code> and <code class="gatsby-code-text">react-dom</code> supporting Hooks is <code class="gatsby-code-text">16.7.0-alpha.0</code>. We expect to publish more alphas over the next months (at the time of writing, the latest one is <code class="gatsby-code-text">16.7.0-alpha.2</code>). You can try them by installing <code class="gatsby-code-text">react@next</code> with <code class="gatsby-code-text">react-dom@next</code>. Don’t forget to update <code class="gatsby-code-text">react-dom</code> — otherwise Hooks won’t work.</p>
<p><strong>Status in React DOM Server:</strong> The same 16.7 alpha versions of <code class="gatsby-code-text">react-dom</code> fully support Hooks with <code class="gatsby-code-text">react-dom/server</code>.</p>
<p><strong>Status in React Native:</strong> There is no officially supported way to try Hooks in React Native yet. If you’re feeling adventurous, check out <a href="https://github.com/facebook/react-native/issues/21967" target="_blank" rel="nofollow noopener noreferrer">this thread</a> for unofficial instructions. There is a known issue with <code class="gatsby-code-text">useEffect</code> firing too late which still needs to be solved.</p>
<p><strong>Recommendation:</strong> When you’re ready, we encourage you to start trying Hooks in new components you write. Make sure everyone on your team is on board with using them and familiar with this documentation. We don’t recommend rewriting your existing classes to Hooks unless you planned to rewrite them anyway (e.g. to fix bugs). Read more about the adoption strategy <a href="/docs/hooks-faq.html#adoption-strategy">here</a>.</p>
<h3 id="react-16x-q2-2019-the-one-with-concurrent-mode"><a href="#react-16x-q2-2019-the-one-with-concurrent-mode" aria-hidden="true" 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 16.x (~Q2 2019): The One with Concurrent Mode </h3>
<p><em>Concurrent Mode</em> lets React apps be more responsive by rendering component trees without blocking the main thread. It is opt-in and allows React to interrupt a long-running render (for example, rendering a new feed story) to handle a high-priority event (for example, text input or hover). Concurrent Mode also improves the user experience of Suspense by skipping unnecessary loading states on fast connections.</p>
<blockquote>
<p>Note</p>
<p>You might have previously heard Concurrent Mode being referred to as <a href="/blog/2018/03/27/update-on-async-rendering.html">“async mode”</a>. We’ve changed the name to Concurrent Mode to highlight React’s ability to perform work on different priority levels. This sets it apart from other approaches to async rendering.</p>
</blockquote>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token comment">// Two ways to opt in:</span>

<span class="token comment">// 1. Part of an app (not final API)</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>React.unstable_ConcurrentMode</span><span class="token punctuation">></span></span><span class="token plain-text">
  </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Something</span> <span class="token punctuation">/></span></span><span class="token plain-text">
</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>React.unstable_ConcurrentMode</span><span class="token punctuation">></span></span>

<span class="token comment">// 2. Whole app (not final API)</span>
ReactDOM<span class="token punctuation">.</span><span class="token function">unstable_createRoot</span><span class="token punctuation">(</span>domNode<span class="token punctuation">)</span><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>App</span> <span class="token punctuation">/></span></span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>There is no documentation written for the Concurrent Mode yet. It is important to highlight that the conceptual model will likely be unfamiliar at first. Documenting its benefits, how to use it efficiently, and its pitfalls is a high priority for us, and will be a prerequisite for calling it stable. Until then, <a href="https://www.youtube.com/watch?v=ByBPyMBTzM0" target="_blank" rel="nofollow noopener noreferrer">Andrew’s talk</a> is the best introduction available.</p>
<p>Concurrent Mode is <em>much</em> less polished than Hooks. Some APIs aren’t properly “wired up” yet and don’t do what they’re expected to. At the time of writing this post, we don’t recommend using it for anything except very early experimentation. We don’t expect many bugs in Concurrent Mode itself, but note that components that produce warnings in <a href="https://reactjs.org/docs/strict-mode.html" target="_blank" rel="nofollow noopener noreferrer"><code class="gatsby-code-text">&lt;React.StrictMode&gt;</code></a> may not work correctly. On a separate note, we’ve seen that Concurrent Mode <em>surfaces</em> performance problems in other code which can sometimes be mistaken for performance issues in Concurrent Mode itself. For example, a stray <code class="gatsby-code-text">setInterval(fn, 1)</code> call that runs every millisecond would have a worse effect in Concurrent Mode. We plan to publish more guidance about diagnosing and fixing issues like this as part of this release’s documentation.</p>
<p>Concurrent Mode is a big part of our vision for React. For CPU-bound work, it allows non-blocking rendering and keeps your app responsive while rendering complex component trees. That’s demoed in the first part of <a href="/blog/2018/03/01/sneak-peek-beyond-react-16.html">our JSConf Iceland talk</a>. Concurrent Mode also makes Suspense better. It lets you avoid flickering a loading indicator if the network is fast enough. It’s hard to explain without seeing so <a href="https://www.youtube.com/watch?v=ByBPyMBTzM0" target="_blank" rel="nofollow noopener noreferrer">Andrew’s talk</a> is the best resource available today. Concurrent Mode relies on a cooperative main thread <a href="https://github.com/facebook/react/tree/master/packages/scheduler" target="_blank" rel="nofollow noopener noreferrer">scheduler</a>, and we are <a href="https://www.youtube.com/watch?v=mDdgfyRB5kg" target="_blank" rel="nofollow noopener noreferrer">collaborating with the Chrome team</a> to eventually move this functionality into the browser itself.</p>
<p><strong>Status in React DOM:</strong> A <em>very</em> unstable version of Concurrent Mode is available behind an <code class="gatsby-code-text">unstable_</code> prefix in React 16.6 but we don’t recommend trying it unless you’re willing to often run into walls or missing features. The 16.7 alphas include <code class="gatsby-code-text">React.ConcurrentMode</code> and <code class="gatsby-code-text">ReactDOM.createRoot</code> without an <code class="gatsby-code-text">unstable_</code> prefix, but we’ll likely keep the prefix in 16.7, and only document and mark Concurrent Mode as stable in this future minor release.</p>
<p><strong>Status in React DOM Server:</strong> Concurrent Mode doesn’t directly affect server rendering. It will work with the existing server renderer.</p>
<p><strong>Status in React Native:</strong> The current plan is to delay enabling Concurrent Mode in React Native until <a href="https://github.com/react-native-community/discussions-and-proposals/issues/4" target="_blank" rel="nofollow noopener noreferrer">React Fabric</a> project is near completion.</p>
<p><strong>Recommendation:</strong> If you wish to adopt Concurrent Mode in the future, wrapping some component subtrees in <a href="https://reactjs.org/docs/strict-mode.html" target="_blank" rel="nofollow noopener noreferrer"><code class="gatsby-code-text">&lt;React.StrictMode&gt;</code></a> and fixing the resulting warnings is a good first step. In general it’s not expected that legacy code would immediately be compatible. For example, at Facebook we mostly intend to use the Concurrent Mode in the more recently developed codebases, and keep the legacy ones running in the synchronous mode for the near future.</p>
<h3 id="react-16x-mid-2019-the-one-with-suspense-for-data-fetching"><a href="#react-16x-mid-2019-the-one-with-suspense-for-data-fetching" aria-hidden="true" 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 16.x (~mid 2019): The One with Suspense for Data Fetching </h3>
<p>As mentioned earlier, <em>Suspense</em> refers to React’s ability to “suspend” rendering while components are waiting for something, and display a loading indicator. In the already shipped React 16.6, the only supported use case for Suspense is code splitting. In this future minor release, we’d like to provide officially supported ways to use it for data fetching too. We’ll provide a reference implementation of a basic “React Cache” that’s compatible with Suspense, but you can also write your own. Data fetching libraries like Apollo and Relay will be able to integrate with Suspense by following a simple specification that we’ll document.</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token comment">// React Cache for simple data fetching (not final API)</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span>unstable_createResource<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'react-cache'</span><span class="token punctuation">;</span>

<span class="token comment">// Tell React Cache how to fetch your data</span>
<span class="token keyword">const</span> TodoResource <span class="token operator">=</span> <span class="token function">unstable_createResource</span><span class="token punctuation">(</span>fetchTodo<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">function</span> <span class="token function">Todo</span><span class="token punctuation">(</span>props<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">// Suspends until the data is in the cache</span>
  <span class="token keyword">const</span> todo <span class="token operator">=</span> TodoResource<span class="token punctuation">.</span><span class="token function">read</span><span class="token punctuation">(</span>props<span class="token punctuation">.</span>id<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">return</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span><span class="token punctuation">></span></span><span class="token punctuation">{</span>todo<span class="token punctuation">.</span>title<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">function</span> <span class="token function">App</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span>
    <span class="token comment">// Same Suspense component you already use for code splitting</span>
    <span class="token comment">// would be able to handle data fetching too.</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>React.Suspense</span> <span class="token attr-name">fallback</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Spinner</span> <span class="token punctuation">/></span></span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span><span class="token plain-text">
      </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ul</span><span class="token punctuation">></span></span><span class="token plain-text">
        </span><span class="token punctuation">{</span><span class="token comment">/* Siblings fetch in parallel */</span><span class="token punctuation">}</span><span class="token plain-text">
        </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Todo</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span><span class="token plain-text">
        </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Todo</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>2<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span><span class="token plain-text">
      </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span class="token punctuation">></span></span><span class="token plain-text">
    </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>React.Suspense</span><span class="token punctuation">></span></span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// Other libraries like Apollo and Relay can also</span>
<span class="token comment">// provide Suspense integrations with similar APIs.</span></code></pre></div>
<p>There is no official documentation for how to fetch data with Suspense yet, but you can find some early information in <a href="https://youtu.be/ByBPyMBTzM0?t=1312" target="_blank" rel="nofollow noopener noreferrer">this talk</a> and <a href="https://github.com/facebook/react/tree/master/fixtures/unstable-async/suspense" target="_blank" rel="nofollow noopener noreferrer">this small demo</a>. We’ll write documentation for React Cache (and how to write your own Suspense-compatible library) closer to this React release, but if you’re curious, you can find its very early source code <a href="https://github.com/facebook/react/blob/master/packages/react-cache/src/ReactCache.js" target="_blank" rel="nofollow noopener noreferrer">here</a>.</p>
<p>The low-level Suspense mechanism (suspending rendering and showing a fallback) is expected to be stable even in React 16.6. We’ve used it for code splitting in production for months. However, the higher-level APIs for data fetching are very unstable. React Cache is rapidly changing, and will change at least a few more times. There are some low-level APIs that are <a href="https://github.com/reactjs/rfcs/pull/89" target="_blank" rel="nofollow noopener noreferrer">missing</a> for a good higher-level API to be possible. We don’t recommend using React Cache anywhere except very early experiments. Note that React Cache itself isn’t strictly tied to React releases, but the current alphas lack basic features as cache invalidation, and you’ll run into a wall very soon. We expect to have something usable with this React release.</p>
<p>Eventually we’d like most data fetching to happen through Suspense but it will take a long time until all integrations are ready. In practice we expect it to be adopted very incrementally, and often through layers like Apollo or Relay rather than directly. Missing higher level APIs aren’t the only obstacle — there are also some important UI patterns we don’t support yet such as <a href="https://github.com/facebook/react/issues/14248" target="_blank" rel="nofollow noopener noreferrer">showing progress indicator outside of the loading view hierarchy</a>. As always, we will communicate our progress in the release notes on this blog.</p>
<p><strong>Status in React DOM and React Native:</strong> Technically, a compatible cache would already work with <code class="gatsby-code-text">&lt;React.Suspense&gt;</code> in React 16.6. However, we don’t expect to have a good cache implementation until this React minor release. If you’re feeling adventurous, you can try to write your own cache by looking at the React Cache alphas. However, note that the mental model is sufficiently different that there’s a high risk of misunderstanding it until the docs are ready.</p>
<p><strong>Status in React DOM Server:</strong> Suspense is not available in the server renderer yet. As we mentioned earlier, we’ve started work on a new asynchronous server renderer that will support Suspense, but it’s a large project and will take a good chunk of 2019 to complete.</p>
<p><strong>Recommendation:</strong> Wait for this minor React release in order to use Suspense for data fetching. Don’t try to use Suspense features in 16.6 for it; it’s not supported. However, your existing <code class="gatsby-code-text">&lt;Suspense&gt;</code> components for code splitting will be able to show loading states for data too when Suspense for Data Fetching becomes officially supported.</p>
<h2 id="other-projects"><a href="#other-projects" aria-hidden="true" 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>Other Projects </h2>
<h3 id="modernizing-react-dom"><a href="#modernizing-react-dom" aria-hidden="true" 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>Modernizing React DOM </h3>
<p>We started an investigation into <a href="https://github.com/facebook/react/issues/13525" target="_blank" rel="nofollow noopener noreferrer">simplifying and modernizing</a> ReactDOM, with a goal of reduced bundle size and aligning closer with the browser behavior. It is still early to say which specific bullet points will “make it” because the project is in an exploratory phase. We will communicate our progress on that issue.</p>
<h3 id="suspense-for-server-rendering"><a href="#suspense-for-server-rendering" aria-hidden="true" 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>Suspense for Server Rendering </h3>
<p>We started designing a new server renderer that supports Suspense (including waiting for asynchronous data on the server without double rendering) and progressively loading and hydrating page content in chunks for best user experience. You can watch an overview of its early prototype in <a href="https://www.youtube.com/watch?v=z-6JC0_cOns" target="_blank" rel="nofollow noopener noreferrer">this talk</a>. The new server renderer is going to be our major focus in 2019, but it’s too early to say anything about its release schedule. Its development, as always, <a href="https://github.com/facebook/react/pulls?utf8=%E2%9C%93&#x26;q=is%3Apr+is%3Aopen+fizz" target="_blank" rel="nofollow noopener noreferrer">will happen on GitHub</a>.</p>
<hr>
<p>And that’s about it! As you can see, there’s a lot here to keep us busy but we expect much progress in the coming months.</p>
<p>We hope this post gives you an idea of what we’re working on, what you can use today, and what you can expect to use in the future. While there’s a lot of discussion about new features on social media platforms, you won’t miss anything important if you read this blog.</p>
<p>We’re always open to feedback, and love to hear from you in the <a href="https://github.com/reactjs/rfcs" target="_blank" rel="nofollow noopener noreferrer">RFC repository</a>, <a href="https://github.com/facebook/react/issues" target="_blank" rel="nofollow noopener noreferrer">the issue tracker</a>, and <a href="https://mobile.twitter.com/reactjs" target="_blank" rel="nofollow noopener noreferrer">on Twitter</a>.</p>]]></description><link>https://reactjs.org/blog/2018/11/27/react-16-roadmap.html</link><guid isPermaLink="false">https://reactjs.org/blog/2018/11/27/react-16-roadmap.html</guid><pubDate>Tue, 27 Nov 2018 00:00:00 GMT</pubDate></item><item><title><![CDATA[React Conf recap: Hooks, Suspense, and Concurrent Rendering]]></title><description><![CDATA[<p>This year’s <a href="https://conf.reactjs.org/" target="_blank" rel="nofollow noopener noreferrer">React Conf</a> took place on October 25 and 26 in Henderson, Nevada, where more than 600 attendees gathered to discuss the latest in UI engineering.</p>
<br>
<div>
          <div
            class="gatsby-resp-iframe-wrapper"
            style="padding-bottom: 56.25%; position: relative; height: 0; overflow: hidden;"
          >
            <iframe src="https://www.youtube.com/embed/V-QO-KO90iQ" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen style="
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
          "></iframe>
          </div>
          </div>
<p>Sophie Alpert and Dan Abramov kicked off Day 1 with their keynote, React Today and Tomorrow. In the talk, they introduced <a href="/docs/hooks-intro.html">Hooks</a>, which are a new proposal that adds the ability to access features such as state without writing a JavaScript class. Hooks promise to dramatically simplify the code required for React components and are currently available in a React alpha release.</p>
<br>
<div>
          <div
            class="gatsby-resp-iframe-wrapper"
            style="padding-bottom: 56.25%; position: relative; height: 0; overflow: hidden;"
          >
            <iframe src="https://www.youtube.com/embed/ByBPyMBTzM0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen style="
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
          "></iframe>
          </div>
          </div>
<p>On the morning of Day 2, Andrew Clark and Brian Vaughn presented Concurrent Rendering in React. Andrew covered the recently announced <a href="/blog/2018/10/23/react-v-16-6.html">React.lazy API for code splitting</a> and previewed two upcoming features: concurrent mode and Suspense. Brian demonstrated how to use <a href="/blog/2018/09/10/introducing-the-react-profiler.html">React’s new profiler</a> tooling to make apps built in React run faster.</p>
<br>
<div>
          <div
            class="gatsby-resp-iframe-wrapper"
            style="padding-bottom: 56.25%; position: relative; height: 0; overflow: hidden;"
          >
            <iframe src="https://www.youtube.com/embed/UcqRXTriUVI" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen style="
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
          "></iframe>
          </div>
          </div>
<p>In the afternoon, Parashuram N spoke in detail about React Native’s New Architecture, a long-term project that the React Native team has been working on over the past year and <a href="https://facebook.github.io/react-native/blog/2018/06/14/state-of-react-native-2018" target="_blank" rel="nofollow noopener noreferrer">announced in June</a>. We’re really excited about the potential of this project to improve performance, simplify interoperability with other libraries, and set a strong foundation for the future of React Native.</p>
<p>Now that the conference is over, all 28 conference talks are <a href="https://www.youtube.com/playlist?list=PLPxbbTqCLbGE5AihOSExAa4wUM-P42EIJ" target="_blank" rel="nofollow noopener noreferrer">available to stream online</a>. There are tons of great ones from both days. We can’t wait until next year!</p>]]></description><link>https://reactjs.org/blog/2018/11/13/react-conf-recap.html</link><guid isPermaLink="false">https://reactjs.org/blog/2018/11/13/react-conf-recap.html</guid><pubDate>Tue, 13 Nov 2018 00:00:00 GMT</pubDate></item><item><title><![CDATA[React v16.6.0: lazy, memo and contextType]]></title><description><![CDATA[<p>Today we’re releasing React 16.6 with a few new convenient features. A form of PureComponent/shouldComponentUpdate for function components, a way to do code splitting using Suspense and an easier way to consume Context from class components.</p>
<p>Check out the full <a href="#changelog">changelog</a> below.</p>
<h2 id="reactmemo"><a href="#reactmemo" aria-hidden="true" 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><a href="/docs/react-api.html#reactmemo"><code class="gatsby-code-text">React.memo</code></a> </h2>
<p>Class components can bail out from rendering when their input props are the same using <a href="/docs/react-api.html#reactpurecomponent"><code class="gatsby-code-text">PureComponent</code></a> or <a href="/docs/react-component.html#shouldcomponentupdate"><code class="gatsby-code-text">shouldComponentUpdate</code></a>. Now you can do the same with function components by wrapping them in <a href="/docs/react-api.html#reactmemo"><code class="gatsby-code-text">React.memo</code></a>.</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">const</span> MyComponent <span class="token operator">=</span> React<span class="token punctuation">.</span><span class="token function">memo</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token function">MyComponent</span><span class="token punctuation">(</span>props<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">/* only rerenders if props change */</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<h2 id="reactlazy-code-splitting-with-suspense"><a href="#reactlazy-code-splitting-with-suspense" aria-hidden="true" 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><a href="/docs/code-splitting.html#reactlazy"><code class="gatsby-code-text">React.lazy</code></a>: Code-Splitting with <code class="gatsby-code-text">Suspense</code> </h2>
<p>You may have seen <a href="/blog/2018/03/01/sneak-peek-beyond-react-16.html">Dan’s talk about React Suspense at JSConf Iceland</a>. Now you can use the Suspense component to do <a href="/docs/code-splitting.html#reactlazy">code-splitting</a> by wrapping a dynamic import in a call to <code class="gatsby-code-text">React.lazy()</code>.</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">import</span> React<span class="token punctuation">,</span> <span class="token punctuation">{</span>lazy<span class="token punctuation">,</span> Suspense<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'react'</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> OtherComponent <span class="token operator">=</span> <span class="token function">lazy</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'./OtherComponent'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword">function</span> <span class="token function">MyComponent</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Suspense</span> <span class="token attr-name">fallback</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">></span></span><span class="token plain-text">Loading...</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span><span class="token plain-text">
      </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>OtherComponent</span> <span class="token punctuation">/></span></span><span class="token plain-text">
    </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Suspense</span><span class="token punctuation">></span></span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The Suspense component will also allow library authors to start building data fetching with Suspense support in the future.</p>
<blockquote>
<p>Note: This feature is not yet available for server-side rendering. Suspense support will be added in a later release.</p>
</blockquote>
<h2 id="static-contexttype"><a href="#static-contexttype" aria-hidden="true" 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><a href="/docs/context.html#classcontexttype"><code class="gatsby-code-text">static contextType</code></a> </h2>
<p>In <a href="/blog/2018/03/29/react-v-16-3.html">React 16.3</a> we introduced the official Context API as a replacement to the previous <a href="/docs/legacy-context.html">Legacy Context</a> API.</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">const</span> MyContext <span class="token operator">=</span> React<span class="token punctuation">.</span><span class="token function">createContext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>We’ve heard feedback that adopting the new render prop API can be difficult in class components. So we’ve added a convenience API to <a href="/docs/context.html#classcontexttype">consume a context value from within a class component</a>.</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">class</span> <span class="token class-name">MyClass</span> <span class="token keyword">extends</span> <span class="token class-name">React<span class="token punctuation">.</span>Component</span> <span class="token punctuation">{</span>
  <span class="token keyword">static</span> contextType <span class="token operator">=</span> MyContext<span class="token punctuation">;</span>
  <span class="token function">componentDidMount</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">let</span> value <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>context<span class="token punctuation">;</span>
    <span class="token comment">/* perform a side-effect at mount using the value of MyContext */</span>
  <span class="token punctuation">}</span>
  <span class="token function">componentDidUpdate</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">let</span> value <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>context<span class="token punctuation">;</span>
    <span class="token comment">/* ... */</span>
  <span class="token punctuation">}</span>
  <span class="token function">componentWillUnmount</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">let</span> value <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>context<span class="token punctuation">;</span>
    <span class="token comment">/* ... */</span>
  <span class="token punctuation">}</span>
  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">let</span> value <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>context<span class="token punctuation">;</span>
    <span class="token comment">/* render something based on the value of MyContext */</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<h2 id="static-getderivedstatefromerror"><a href="#static-getderivedstatefromerror" aria-hidden="true" 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><a href="/docs/react-component.html#static-getderivedstatefromerror"><code class="gatsby-code-text">static getDerivedStateFromError()</code></a> </h2>
<p>React 16 introduced <a href="/blog/2017/07/26/error-handling-in-react-16.html">Error Boundaries</a> for handling errors thrown in React renders. We already had the <code class="gatsby-code-text">componentDidCatch</code> lifecycle method which gets fired after an error has already happened. It’s great for logging errors to the server. It also lets you show a different UI to the user by calling <code class="gatsby-code-text">setState</code>.</p>
<p>Before that is fired, we render <code class="gatsby-code-text">null</code> in place of the tree that threw an error. This sometimes breaks parent components that don’t expect their refs to be empty. It also doesn’t work to recover from errors on the server since the <code class="gatsby-code-text">Did</code> lifecycle methods don’t fire during server-side rendering.</p>
<p>We’re adding another error method that lets you render the fallback UI before the render completes. See the docs for <a href="/docs/react-component.html#static-getderivedstatefromerror"><code class="gatsby-code-text">getDerivedStateFromError()</code></a>.</p>
<blockquote>
<p>Note: <code class="gatsby-code-text">getDerivedStateFromError()</code> is not yet available for server-side rendering. It is designed to work with server-side rendering in a future release. We’re releasing it early so that you can start preparing to use it.</p>
</blockquote>
<h2 id="deprecations-in-strictmode"><a href="#deprecations-in-strictmode" aria-hidden="true" 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>Deprecations in StrictMode </h2>
<p>In <a href="/blog/2018/03/29/react-v-16-3.html#strictmode-component">16.3</a> we introduced the <a href="/docs/strict-mode.html"><code class="gatsby-code-text">StrictMode</code></a> component. It lets you opt-in to early warnings for patterns that might cause problems in the future.</p>
<p>We’ve added two more APIs to the list of deprecated APIs in <code class="gatsby-code-text">StrictMode</code>. If you don’t use <code class="gatsby-code-text">StrictMode</code> you don’t have to worry; these warning won’t fire for you.</p>
<ul>
<li><strong>ReactDOM.findDOMNode()</strong> - This API is often misunderstood and most uses of it are unnecessary. It can also be surprisingly slow in React 16. <a href="/docs/strict-mode.html#warning-about-deprecated-finddomnode-usage">See the docs</a> for possible upgrade paths.</li>
<li><strong>Legacy Context</strong> using contextTypes and getChildContext - Legacy context makes React slightly slower and bigger than it needs to be. That’s why we strongly want to encourage upgrading to the <a href="/docs/context.html">new context API</a>. Hopefully the addition of the <a href="/docs/context.html#classcontexttype"><code class="gatsby-code-text">contextType</code></a> API makes this a bit easier.</li>
</ul>
<p>If you’re having trouble upgrading, we’d like to hear your feedback.</p>
<h2 id="installation"><a href="#installation" aria-hidden="true" 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>
<p>React v16.6.0 is available on the npm registry.</p>
<p>To install React 16 with Yarn, run:</p>
<div class="gatsby-highlight" data-language="bash"><pre class="gatsby-code-bash"><code class="gatsby-code-bash">yarn add react@^16.6.0 react-dom@^16.6.0</code></pre></div>
<p>To install React 16 with npm, run:</p>
<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.6.0 react-dom@^16.6.0</code></pre></div>
<p>We also provide UMD builds of React via a CDN:</p>
<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">=</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 language-javascript"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">></span></span>
<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">=</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 language-javascript"></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>
<p>Refer to the documentation for <a href="/docs/installation.html">detailed installation instructions</a>.</p>
<h2 id="changelog"><a href="#changelog" aria-hidden="true" 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>
<h3 id="react"><a href="#react" aria-hidden="true" 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>
<ul>
<li>Add <code class="gatsby-code-text">React.memo()</code> as an alternative to <code class="gatsby-code-text">PureComponent</code> for functions. (<a href="https://github.com/acdlite" target="_blank" rel="nofollow noopener noreferrer">@acdlite</a> in <a href="https://github.com/facebook/react/pull/13748" target="_blank" rel="nofollow noopener noreferrer">#13748</a>)</li>
<li>Add <code class="gatsby-code-text">React.lazy()</code> for code splitting components. (<a href="https://github.com/acdlite" target="_blank" rel="nofollow noopener noreferrer">@acdlite</a> in <a href="https://github.com/facebook/react/pull/13885" target="_blank" rel="nofollow noopener noreferrer">#13885</a>)</li>
<li><code class="gatsby-code-text">React.StrictMode</code> now warns about legacy context API. (<a href="https://github.com/bvaughn" target="_blank" rel="nofollow noopener noreferrer">@bvaughn</a> in <a href="https://github.com/facebook/react/pull/13760" target="_blank" rel="nofollow noopener noreferrer">#13760</a>)</li>
<li><code class="gatsby-code-text">React.StrictMode</code> now warns about <code class="gatsby-code-text">findDOMNode</code>. (<a href="https://github.com/sebmarkbage" target="_blank" rel="nofollow noopener noreferrer">@sebmarkbage</a> in <a href="https://github.com/facebook/react/pull/13841" target="_blank" rel="nofollow noopener noreferrer">#13841</a>)</li>
<li>Rename <code class="gatsby-code-text">unstable_AsyncMode</code> to <code class="gatsby-code-text">unstable_ConcurrentMode</code>. (<a href="https://github.com/trueadm" target="_blank" rel="nofollow noopener noreferrer">@trueadm</a> in <a href="https://github.com/facebook/react/pull/13732" target="_blank" rel="nofollow noopener noreferrer">#13732</a>)</li>
<li>Rename <code class="gatsby-code-text">unstable_Placeholder</code> to <code class="gatsby-code-text">Suspense</code>, and <code class="gatsby-code-text">delayMs</code> to <code class="gatsby-code-text">maxDuration</code>. (<a href="https://github.com/gaearon" target="_blank" rel="nofollow noopener noreferrer">@gaearon</a> in <a href="https://github.com/facebook/react/pull/13799" target="_blank" rel="nofollow noopener noreferrer">#13799</a> and <a href="https://github.com/sebmarkbage" target="_blank" rel="nofollow noopener noreferrer">@sebmarkbage</a> in <a href="https://github.com/facebook/react/pull/13922" target="_blank" rel="nofollow noopener noreferrer">#13922</a>)</li>
</ul>
<h3 id="react-dom"><a href="#react-dom" aria-hidden="true" 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>
<ul>
<li>Add <code class="gatsby-code-text">contextType</code> as a more ergonomic way to subscribe to context from a class. (<a href="https://github.com/bvaughn" target="_blank" rel="nofollow noopener noreferrer">@bvaughn</a> in <a href="https://github.com/facebook/react/pull/13728" target="_blank" rel="nofollow noopener noreferrer">#13728</a>)</li>
<li>Add <code class="gatsby-code-text">getDerivedStateFromError</code> lifecycle method for catching errors in a future asynchronous server-side renderer. (<a href="https://github.com/bvaughn" target="_blank" rel="nofollow noopener noreferrer">@bvaughn</a> in <a href="https://github.com/facebook/react/pull/13746" target="_blank" rel="nofollow noopener noreferrer">#13746</a>)</li>
<li>Warn when <code class="gatsby-code-text">&lt;Context&gt;</code> is used instead of <code class="gatsby-code-text">&lt;Context.Consumer&gt;</code>. (<a href="https://github.com/trueadm" target="_blank" rel="nofollow noopener noreferrer">@trueadm</a> in <a href="https://github.com/facebook/react/pull/13829" target="_blank" rel="nofollow noopener noreferrer">#13829</a>)</li>
<li>Fix gray overlay on iOS Safari. (<a href="https://github.com/philipp-spiess" target="_blank" rel="nofollow noopener noreferrer">@philipp-spiess</a> in <a href="https://github.com/facebook/react/pull/13778" target="_blank" rel="nofollow noopener noreferrer">#13778</a>)</li>
<li>Fix a bug caused by overwriting <code class="gatsby-code-text">window.event</code> in development. (<a href="https://github.com/sergei-startsev" target="_blank" rel="nofollow noopener noreferrer">@sergei-startsev</a> in <a href="https://github.com/facebook/react/pull/13697" target="_blank" rel="nofollow noopener noreferrer">#13697</a>)</li>
</ul>
<h3 id="react-dom-server"><a href="#react-dom-server" aria-hidden="true" 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 Server </h3>
<ul>
<li>Add support for <code class="gatsby-code-text">React.memo()</code>. (<a href="https://github.com/alexmckenley" target="_blank" rel="nofollow noopener noreferrer">@alexmckenley</a> in <a href="https://github.com/facebook/react/pull/13855" target="_blank" rel="nofollow noopener noreferrer">#13855</a>)</li>
<li>Add support for <code class="gatsby-code-text">contextType</code>. (<a href="https://github.com/alexmckenley" target="_blank" rel="nofollow noopener noreferrer">@alexmckenley</a> and <a href="https://github.com/sebmarkbage" target="_blank" rel="nofollow noopener noreferrer">@sebmarkbage</a> in <a href="https://github.com/facebook/react/pull/13889" target="_blank" rel="nofollow noopener noreferrer">#13889</a>)</li>
</ul>
<h3 id="scheduler-experimental"><a href="#scheduler-experimental" aria-hidden="true" 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>Scheduler (Experimental) </h3>
<ul>
<li>Rename the package to <code class="gatsby-code-text">scheduler</code>. (<a href="https://github.com/gaearon" target="_blank" rel="nofollow noopener noreferrer">@gaearon</a> in <a href="https://github.com/facebook/react/pull/13683" target="_blank" rel="nofollow noopener noreferrer">#13683</a>)</li>
<li>Support priority levels, continuations, and wrapped callbacks. (<a href="https://github.com/acdlite" target="_blank" rel="nofollow noopener noreferrer">@acdlite</a> in <a href="https://github.com/facebook/react/pull/13720" target="_blank" rel="nofollow noopener noreferrer">#13720</a> and <a href="https://github.com/facebook/react/pull/13842" target="_blank" rel="nofollow noopener noreferrer">#13842</a>)</li>
<li>Improve the fallback mechanism in non-DOM environments. (<a href="https://github.com/acdlite" target="_blank" rel="nofollow noopener noreferrer">@acdlite</a> in <a href="https://github.com/facebook/react/pull/13740" target="_blank" rel="nofollow noopener noreferrer">#13740</a>)</li>
<li>Schedule <code class="gatsby-code-text">requestAnimationFrame</code> earlier. (<a href="https://github.com/acdlite" target="_blank" rel="nofollow noopener noreferrer">@acdlite</a> in <a href="https://github.com/facebook/react/pull/13785" target="_blank" rel="nofollow noopener noreferrer">#13785</a>)</li>
<li>Fix the DOM detection to be more thorough. (<a href="https://github.com/trueadm" target="_blank" rel="nofollow noopener noreferrer">@trueadm</a> in <a href="https://github.com/facebook/react/pull/13731" target="_blank" rel="nofollow noopener noreferrer">#13731</a>)</li>
<li>Fix bugs with interaction tracing. (<a href="https://github.com/bvaughn" target="_blank" rel="nofollow noopener noreferrer">@bvaughn</a> in <a href="https://github.com/facebook/react/pull/13590" target="_blank" rel="nofollow noopener noreferrer">#13590</a>)</li>
<li>Add the <code class="gatsby-code-text">envify</code> transform to the package. (<a href="https://github.com/mridgway" target="_blank" rel="nofollow noopener noreferrer">@mridgway</a> in <a href="https://github.com/facebook/react/pull/13766" target="_blank" rel="nofollow noopener noreferrer">#13766</a>)</li>
</ul>]]></description><link>https://reactjs.org/blog/2018/10/23/react-v-16-6.html</link><guid isPermaLink="false">https://reactjs.org/blog/2018/10/23/react-v-16-6.html</guid><pubDate>Tue, 23 Oct 2018 00:00:00 GMT</pubDate></item><item><title><![CDATA[Create React App 2.0: Babel 7, Sass, and More]]></title><description><![CDATA[<p>Create React App 2.0 has been released today, and it brings a year’s worth of improvements in a single dependency update.</p>
<p>While React itself <a href="/docs/create-a-new-react-app.html">doesn’t require any build dependencies</a>, it can be challenging to write a complex app without a fast test runner, a production minifier, and a modular codebase. Since the very first release, the goal of <a href="https://github.com/facebook/create-react-app" target="_blank" rel="nofollow noopener noreferrer">Create React App</a> has been to help you focus on what matters the most — your application code — and to handle build and testing setup for you.</p>
<p>Many of the tools it relies on have since released new versions containing new features and performance improvements: <a href="https://babeljs.io/blog/2018/08/27/7.0.0" target="_blank" rel="nofollow noopener noreferrer">Babel 7</a>, <a href="https://medium.com/webpack/webpack-4-released-today-6cdb994702d4" target="_blank" rel="nofollow noopener noreferrer">webpack 4</a>, and <a href="https://jestjs.io/blog/2018/05/29/jest-23-blazing-fast-delightful-testing.html" target="_blank" rel="nofollow noopener noreferrer">Jest 23</a>. However, updating them manually and making them work well together takes a lot of effort. And this is exactly what <a href="https://github.com/facebook/create-react-app/graphs/contributors" target="_blank" rel="nofollow noopener noreferrer">Create React App 2.0 contributors</a> have been busy with for the past few months: <strong>migrating the configuration and dependencies so that you don’t need to do it yourself.</strong></p>
<p>Now that Create React App 2.0 is out of beta, let’s see what’s new and how you can try it!</p>
<blockquote>
<p>Note</p>
<p>Don’t feel pressured to upgrade anything. If you’re satisfied with the current feature set, its performance, and reliability, you can keep using the version you’re currently at! It might also be a good idea to let the 2.0 release stabilize a little bit before switching to it in production.</p>
</blockquote>
<h2 id="whats-new"><a href="#whats-new" aria-hidden="true" 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 New </h2>
<p>Here’s a short summary of what’s new in this release:</p>
<ul>
<li>🎉 More styling options: you can use <a href="https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-a-sass-stylesheet" target="_blank" rel="nofollow noopener noreferrer">Sass</a> and <a href="https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-a-css-modules-stylesheet" target="_blank" rel="nofollow noopener noreferrer">CSS Modules</a> out of the box.</li>
<li>🐠 We updated to <a href="https://babeljs.io/blog/2018/08/27/7.0.0" target="_blank" rel="nofollow noopener noreferrer">Babel 7</a>, including support for the <a href="/docs/fragments.html#short-syntax">React fragment syntax</a> and many bugfixes.</li>
<li>📦 We updated to <a href="https://medium.com/webpack/webpack-4-released-today-6cdb994702d4" target="_blank" rel="nofollow noopener noreferrer">webpack 4</a>, which automatically splits JS bundles more intelligently.</li>
<li>🃏 We updated to <a href="https://jestjs.io/blog/2018/05/29/jest-23-blazing-fast-delightful-testing.html" target="_blank" rel="nofollow noopener noreferrer">Jest 23</a>, which includes an <a href="https://jestjs.io/blog/2018/05/29/jest-23-blazing-fast-delightful-testing#interactive-snapshot-mode" target="_blank" rel="nofollow noopener noreferrer">interactive mode</a> for reviewing snapshots.</li>
<li>💄 We added <a href="https://preset-env.cssdb.org/features#stage-3" target="_blank" rel="nofollow noopener noreferrer">PostCSS</a> so you can use new CSS features in old browsers.</li>
<li>💎 You can use <a href="https://github.com/leoasis/graphql-tag.macro#usage" target="_blank" rel="nofollow noopener noreferrer">Apollo</a>, <a href="https://github.com/facebook/relay/pull/2171#issuecomment-411459604" target="_blank" rel="nofollow noopener noreferrer">Relay Modern</a>, <a href="https://github.com/facebook/create-react-app/issues/5149#issuecomment-425396995" target="_blank" rel="nofollow noopener noreferrer">MDX</a>, and other third-party <a href="https://babeljs.io/blog/2017/09/11/zero-config-with-babel-macros" target="_blank" rel="nofollow noopener noreferrer">Babel Macros</a> transforms.</li>
<li>🌠 You can now <a href="https://facebook.github.io/create-react-app/docs/adding-images-fonts-and-files#adding-svgs" target="_blank" rel="nofollow noopener noreferrer">import an SVG as a React component</a>, and use it in JSX.</li>
<li>🐈 You can try the experimental <a href="https://github.com/yarnpkg/rfcs/pull/101" target="_blank" rel="nofollow noopener noreferrer">Yarn Plug’n’Play mode</a> that removes <code class="gatsby-code-text">node_modules</code>.</li>
<li>🕸 You can now <a href="https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#configuring-the-proxy-manually" target="_blank" rel="nofollow noopener noreferrer">plug your own proxy implementation</a> in development to match your backend API.</li>
<li>🚀 You can now use <a href="https://github.com/sindresorhus/ama/issues/446#issuecomment-281014491" target="_blank" rel="nofollow noopener noreferrer">packages written for latest Node versions</a> without breaking the build.</li>
<li>✂️ You can now optionally get a smaller CSS bundle if you only plan to target modern browsers.</li>
<li>👷‍♀️ Service workers are now opt-in and are built using Google’s <a href="https://developers.google.com/web/tools/workbox/" target="_blank" rel="nofollow noopener noreferrer">Workbox</a>.</li>
</ul>
<p><strong>All of these features work out of the box</strong> — to enable them, follow the below instructions.</p>
<h2 id="starting-a-project-with-create-react-app-20"><a href="#starting-a-project-with-create-react-app-20" aria-hidden="true" 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>Starting a Project with Create React App 2.0 </h2>
<p>You don’t need to update anything special. Starting from today, when you run <code class="gatsby-code-text">create-react-app</code> it will use the 2.0 version of the template by default. Have fun!</p>
<p>If you want to <strong>use the old 1.x template</strong> for some reason, you can do that by passing <code class="gatsby-code-text">--scripts-version=react-scripts@1.x</code> as an argument to <code class="gatsby-code-text">create-react-app</code>.</p>
<h2 id="updating-a-project-to-create-react-app-20"><a href="#updating-a-project-to-create-react-app-20" aria-hidden="true" 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>Updating a Project to Create React App 2.0 </h2>
<p>Upgrading a non-ejected project to Create React App 2.0 should usually be straightforward. Open <code class="gatsby-code-text">package.json</code> in the root of your project and find <code class="gatsby-code-text">react-scripts</code> there.</p>
<p>Then change its version to <code class="gatsby-code-text">2.0.3</code>:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx">  <span class="token comment">// ... other dependencies ...</span>
<span class="gatsby-highlight-code-line">  <span class="token string">"react-scripts"</span><span class="token punctuation">:</span> <span class="token string">"2.0.3"</span>
</span></code></pre></div>
<p>Run <code class="gatsby-code-text">npm install</code> (or <code class="gatsby-code-text">yarn</code>, if you use it). <strong>For many projects, this one-line change is sufficient to upgrade!</strong></p>
<blockquote class="twitter-tweet" data-conversation="none" data-dnt="true"><p lang="en" dir="ltr">working here... thanks for all the new functionality 👍</p>&mdash; Stephen Haney (@sdothaney) <a href="https://twitter.com/sdothaney/status/1046822703116607490?ref_src=twsrc%5Etfw">October 1, 2018</a></blockquote>
<p>Here are a few more tips to get you started.</p>
<p><strong>When you run <code class="gatsby-code-text">npm start</code> for the first time after the upgrade,</strong> you’ll get a prompt asking about which browsers you’d like to support. Press <code class="gatsby-code-text">y</code> to accept the default ones. They’ll be written to your <code class="gatsby-code-text">package.json</code> and you can edit them any time. Create React App will use this information to produce smaller or polyfilled CSS bundles depending on whether you target modern browsers or older browsers.</p>
<p><strong>If <code class="gatsby-code-text">npm start</code> still doesn’t quite work for you after the upgrade,</strong> <a href="https://github.com/facebook/create-react-app/releases/tag/v2.0.3" target="_blank" rel="nofollow noopener noreferrer">check out the more detailed migration instructions in the release notes</a>. There <em>are</em> a few breaking changes in this release but the scope of them is limited, so they shouldn’t take more than a few hours to sort out. Note that <strong><a href="https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md" target="_blank" rel="nofollow noopener noreferrer">support for older browsers</a> is now opt-in</strong> to reduce the polyfill size.</p>
<p><strong>If you previously ejected but now want to upgrade,</strong> one common solution is to find the commits where you ejected (and any subsequent commits changing the configuration), revert them, upgrade, and later optionally eject again. It’s also possible that the feature you ejected for (maybe Sass or CSS Modules?) is now supported out of the box.</p>
<blockquote>
<p>Note</p>
<p>Due to a possible bug in npm, you might see warnings about unsatisfied peer dependencies. You should be able to ignore them. As far as we’re aware, this issue isn’t present with Yarn.</p>
</blockquote>
<h2 id="breaking-changes"><a href="#breaking-changes" aria-hidden="true" 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>Breaking Changes </h2>
<p>Here’s a short list of breaking changes in this release:</p>
<ul>
<li>Node 6 is no longer supported.</li>
<li>Support for older browsers (such as IE 9 to IE 11) is now opt-in with a <a href="https://github.com/facebook/create-react-app/tree/master/packages/react-app-polyfill" target="_blank" rel="nofollow noopener noreferrer">separate package</a>.</li>
<li>Code-splitting with <code class="gatsby-code-text">import()</code> now behaves closer to specification, while <code class="gatsby-code-text">require.ensure()</code> is disabled.</li>
<li>The default Jest environment now includes jsdom.</li>
<li>Support for specifying an object as <code class="gatsby-code-text">proxy</code> setting was replaced with support for a custom proxy module.</li>
<li>Support for <code class="gatsby-code-text">.mjs</code> extension was removed until the ecosystem around it stabilizes.</li>
<li>PropTypes definitions are automatically stripped out of the production builds.</li>
</ul>
<p>If either of these points affects you, <a href="https://github.com/facebook/create-react-app/releases/tag/v2.0.3" target="_blank" rel="nofollow noopener noreferrer">2.0.3 release notes</a> contain more detailed instructions.</p>
<h2 id="learn-more"><a href="#learn-more" aria-hidden="true" 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>Learn More </h2>
<p>You can find the full changelog in the <a href="https://github.com/facebook/create-react-app/releases/tag/v2.0.3" target="_blank" rel="nofollow noopener noreferrer">release notes</a>. This was a large release, and we may have missed something. Please report any problems to our <a href="https://github.com/facebook/create-react-app/issues/new" target="_blank" rel="nofollow noopener noreferrer">issue tracker</a> and we’ll try to help.</p>
<blockquote>
<p>Note</p>
<p>If you’ve been using 2.x alpha versions, we provide <a href="https://gist.github.com/gaearon/8650d1c70e436e5eff01f396dffc4114" target="_blank" rel="nofollow noopener noreferrer">separate migration instructions</a> for them.</p>
</blockquote>
<h2 id="thanks"><a href="#thanks" aria-hidden="true" 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>
<p>This release wouldn’t be possible without our wonderful community of contributors. We’d like to thank <a href="https://github.com/andriijas" target="_blank" rel="nofollow noopener noreferrer">Andreas Cederström</a>, <a href="https://github.com/clemmy" target="_blank" rel="nofollow noopener noreferrer">Clement Hoang</a>, <a href="https://github.com/existentialism" target="_blank" rel="nofollow noopener noreferrer">Brian Ng</a>, <a href="https://github.com/kentcdodds" target="_blank" rel="nofollow noopener noreferrer">Kent C. Dodds</a>, <a href="https://github.com/viankakrisna" target="_blank" rel="nofollow noopener noreferrer">Ade Viankakrisna Fadlil</a>, <a href="https://github.com/ai" target="_blank" rel="nofollow noopener noreferrer">Andrey Sitnik</a>, <a href="https://github.com/ro-savage" target="_blank" rel="nofollow noopener noreferrer">Ro Savage</a>, <a href="https://github.com/Fabianopb" target="_blank" rel="nofollow noopener noreferrer">Fabiano Brito</a>, <a href="https://github.com/iansu" target="_blank" rel="nofollow noopener noreferrer">Ian Sutherland</a>, <a href="https://github.com/petetnt" target="_blank" rel="nofollow noopener noreferrer">Pete Nykänen</a>, <a href="https://github.com/jeffposnick" target="_blank" rel="nofollow noopener noreferrer">Jeffrey Posnick</a>, <a href="https://github.com/bugzpodder" target="_blank" rel="nofollow noopener noreferrer">Jack Zhao</a>, <a href="https://github.com/sokra" target="_blank" rel="nofollow noopener noreferrer">Tobias Koppers</a>, <a href="https://github.com/hzoo" target="_blank" rel="nofollow noopener noreferrer">Henry Zhu</a>, <a href="https://github.com/arcanis" target="_blank" rel="nofollow noopener noreferrer">Maël Nison</a>, <a href="https://github.com/lixiaoyan" target="_blank" rel="nofollow noopener noreferrer">XiaoYan Li</a>, <a href="https://github.com/themre" target="_blank" rel="nofollow noopener noreferrer">Marko Trebizan</a>, <a href="https://github.com/mareksuscak" target="_blank" rel="nofollow noopener noreferrer">Marek Suscak</a>, <a href="https://github.com/miraage" target="_blank" rel="nofollow noopener noreferrer">Mikhail Osher</a>, and many others who provided feedback and testing for this release.</p>]]></description><link>https://reactjs.org/blog/2018/10/01/create-react-app-v2.html</link><guid isPermaLink="false">https://reactjs.org/blog/2018/10/01/create-react-app-v2.html</guid><pubDate>Mon, 01 Oct 2018 00:00:00 GMT</pubDate></item><item><title><![CDATA[Introducing the React Profiler]]></title><description><![CDATA[<p>React 16.5 adds support for a new DevTools profiler plugin.
This plugin uses React’s <a href="https://github.com/reactjs/rfcs/pull/51" target="_blank" rel="nofollow noopener noreferrer">experimental Profiler API</a> to collect timing information about each component that’s rendered in order to identify performance bottlenecks in React applications.
It will be fully compatible with our upcoming <a href="/blog/2018/03/01/sneak-peek-beyond-react-16.html">time slicing and suspense</a> features.</p>
<p>This blog post covers the following topics:</p>
<ul>
<li><a href="#profiling-an-application">Profiling an application</a></li>
<li>
<p><a href="#reading-performance-data">Reading performance data</a></p>
<ul>
<li><a href="#browsing-commits">Browsing commits</a></li>
<li><a href="#filtering-commits">Filtering commits</a></li>
<li><a href="#flame-chart">Flame chart</a></li>
<li><a href="#ranked-chart">Ranked chart</a></li>
<li><a href="#component-chart">Component chart</a></li>
<li><a href="#interactions">Interactions</a></li>
</ul>
</li>
<li>
<p><a href="#troubleshooting">Troubleshooting</a></p>
<ul>
<li><a href="#no-profiling-data-has-been-recorded-for-the-selected-root">No profiling data has been recorded for the selected root</a></li>
<li><a href="#no-timing-data-to-display-for-the-selected-commit">No timing data to display for the selected commit</a></li>
</ul>
</li>
<li><a href="#deep-dive-video">Deep dive video</a></li>
</ul>
<h2 id="profiling-an-application"><a href="#profiling-an-application" aria-hidden="true" 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>Profiling an application </h2>
<p>DevTools will show a “Profiler” tab for applications that support the new profiling API:</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/devtools-profiler-tab-4da6b55fc3c98de04c261cd902c14dc3-53c76.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 47.82608695652174%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAAB60lEQVQoz62RzW7TQBSFI8Srsekz1BJs2LDkLVjUKGSRxJay6AsgRJtCwwKJqiGNY4fSFhAqUdImkf/GcezxZHw9l5lpQXSBxIIjfTrjY+mTf2qDPXvr7XH34bA/2nbcsTEcjY0TxzMc95Px4ahvvN5/Y3QPDo2Xr/aMo+OB3r2xxPM0rutuSx45jvOgpvLty/l3uiaYXX7FTZYgcIqiLDSVPJcsQ9hkuquSyi1Hmq+RMaYpigJV5vO5q4W94dX5e2+F3YFfHowi6I1jeHeawKFHNL1xcof9YQRnPwgwmgOlFKSLK2GSJB+l7n5ttogvAp/hbBbA9TIRkzkT0yUVYVqKKKtEtIY7hJKsAIHid5QUCSEDLczW6YUa4utFFUwnOJkQvJqGSIIM+YYj54AbXsm+oSxBdonSqF/1D+GJFsZkpYWrZVKlYSyCgIo4osL3C7GKE5FEiTwzEYaFhIo0zgVnXIi/PWGepWdqSBeEp0EEflBAFDIIJSuyBimFwKdACINYkqUMoAQl+QW/Ffa18PNlOFFDSSvcyG+c5yj/ooQiMtmixH9KFEWnWrj12Hz67HnrhW1bO82WZbbbbbPVusFqt0zLkm3ZZlteq3uKZrNp1ut1s9FoKHZs2250Op0nWnibe/+B2u7ubu0n/Rxb5mrVIIgAAAAASUVORK5CYII='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="New DevTools "profiler" tab"
        title=""
        src="/static/devtools-profiler-tab-4da6b55fc3c98de04c261cd902c14dc3-acf85.png"
        srcset="/static/devtools-profiler-tab-4da6b55fc3c98de04c261cd902c14dc3-c1418.png 210w,
/static/devtools-profiler-tab-4da6b55fc3c98de04c261cd902c14dc3-5d5d8.png 420w,
/static/devtools-profiler-tab-4da6b55fc3c98de04c261cd902c14dc3-acf85.png 840w,
/static/devtools-profiler-tab-4da6b55fc3c98de04c261cd902c14dc3-53c76.png 1012w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<blockquote>
<p>Note:</p>
<p><code class="gatsby-code-text">react-dom</code> 16.5+ supports profiling in DEV mode.
A production profiling bundle is also available as <code class="gatsby-code-text">react-dom/profiling</code>.
Read more about how to use this bundle at <a href="https://fb.me/react-profiling" target="_blank" rel="nofollow noopener noreferrer">fb.me/react-profiling</a> </p>
</blockquote>
<p>The “Profiler” panel will be empty initially. Click the record button to start profiling:</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/start-profiling-bae8d10e17f06eeb8c512c91c0153cff-53c76.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 47.82608695652174%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAABdUlEQVQoz62QvU7DMBCAI8SrsfAMjQQzI+9RBthpq0ody9ABMTC0C0lKwo8KDEjt0GZomthJmx8S1+bukkbAiHrSp7OTu89na4+318f347sTe2w3DNPQDaPENE19OBzq/f6NPhgMIPf10WhE3+k/YBkPumPbDcdxTi3LOtIwPiYvnyxkaj53VRAEv/B9Xy2XS7VarZTnIR59Z4xBZsr1AsXDSGFMp1OHhLOn57cszZTP10Ucx+IvSZIQaZqK9XotNpuNkFKK7XYrCkSIHIVwuAG6Q40HwTsdoSQWSlwQ1fpngISoa0oEdnPOTRJGUURCrMdcFAUBI5RZCFX9rzMCYpWXtVQAz2CRMAzDWgjNEvaSeZ5ki4WEUyVcs55qNyWu8zyXcH2Jz1EJzZ1wUgnzLMtEAm+VcC5i1xVfsI+hAZqxqX47zNVVkbwSPpAQJpipPQQM9krCdrt93u12LzudThO4+AdN6L9qtVpnJKziYA9ovV5P+wavR2c66XZI3gAAAABJRU5ErkJggg=='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="Click "record" to start profiling"
        title=""
        src="/static/start-profiling-bae8d10e17f06eeb8c512c91c0153cff-acf85.png"
        srcset="/static/start-profiling-bae8d10e17f06eeb8c512c91c0153cff-c1418.png 210w,
/static/start-profiling-bae8d10e17f06eeb8c512c91c0153cff-5d5d8.png 420w,
/static/start-profiling-bae8d10e17f06eeb8c512c91c0153cff-acf85.png 840w,
/static/start-profiling-bae8d10e17f06eeb8c512c91c0153cff-53c76.png 1012w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<p>Once you’ve started recording, DevTools will automatically collect performance information each time your application renders.
Use your app as you normally would.
When you are finished profiling, click the “Stop” button.</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/stop-profiling-45619de03bed468869f7a0878f220586-53c76.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 47.82608695652174%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAABcklEQVQoz62QS2vCQBCAQ+lf66W/wUB77rH/Qw/tuSQieLSHQMFDD3oxiSQHUfsCC1UP5rGJeTRuNrvd2SRiH/TkwMdkM7PfDiNZD3fnj+P+hTW2Grqhy7peYhiGPBgM5F7vXtY0jeeePBwOxX9R55j6SLYtq2Hb9qVpmmcSxNN08oZCxJbLNfN9/xue57HNZsNc12WOAzjiP0KIZ8TWjs+CcMsgFouFLYQfL6+zLNsxD0V5kiQkTRMCuSZN0z1wzrKM0KIgBScHCMEg5I/rXHcqhQjNxROMEnoQRUH/DC6i0HwAgdtBEBilcLsVQuitMiuo6GF8DPYzoC56eA3nOcvzXDTzNZilMAz3QpgAPlcrl2r9Z/qZJLQs/Z4QY0zjOKawikpo1MJpJcQcKJI03pHZ3CF8DELLVeyB3dV9FbgSjoQwiqJ3doTgg02EUFXV606nc9Nut5ucVo2iqK3D8z80+f1bRVGuhLCKkyMgdbtd6Qtm52eikNUIKgAAAABJRU5ErkJggg=='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="Click "stop" when you are finished profiling"
        title=""
        src="/static/stop-profiling-45619de03bed468869f7a0878f220586-acf85.png"
        srcset="/static/stop-profiling-45619de03bed468869f7a0878f220586-c1418.png 210w,
/static/stop-profiling-45619de03bed468869f7a0878f220586-5d5d8.png 420w,
/static/stop-profiling-45619de03bed468869f7a0878f220586-acf85.png 840w,
/static/stop-profiling-45619de03bed468869f7a0878f220586-53c76.png 1012w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<p>Assuming your application rendered at least once while profiling, DevTools will show several ways to view the performance data.
We’ll <a href="#reading-performance-data">take a look at each of these below</a>.</p>
<h2 id="reading-performance-data"><a href="#reading-performance-data" aria-hidden="true" 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>Reading performance data </h2>
<h3 id="browsing-commits"><a href="#browsing-commits" aria-hidden="true" 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>Browsing commits </h3>
<p>Conceptually, React does work in two phases:</p>
<ul>
<li>The <strong>render</strong> phase determines what changes need to be made to e.g. the DOM. During this phase, React calls <code class="gatsby-code-text">render</code> and then compares the result to the previous render.</li>
<li>The <strong>commit</strong> phase is when React applies any changes. (In the case of React DOM, this is when React inserts, updates, and removes DOM nodes.) React also calls lifecycles like <code class="gatsby-code-text">componentDidMount</code> and <code class="gatsby-code-text">componentDidUpdate</code> during this phase.</li>
</ul>
<p>The DevTools profiler groups performance info by commit.
Commits are displayed in a bar chart near the top of the profiler:</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/commit-selector-bd72dec045515d59be51c944e902d263-8ef72.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 601px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 9.983361064891847%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAACCAIAAADXZGvcAAAACXBIWXMAAAsSAAALEgHS3X78AAAAbUlEQVQI103KuwqEMBBAUf//X7axtLERbLaKuMWC2RDcmcyMeSNYaiWe7sJtAED/DJJ8vuaPUkpJKeWHKxNzRNxly+gq0eH9zpTJNQ5httEC+xBZthD8NZdbrau1pBRPk+ilb1/z2BltQPXxPZwvF2xA6VCC0AAAAABJRU5ErkJggg=='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="Bar chart of profiled commits"
        title=""
        src="/static/commit-selector-bd72dec045515d59be51c944e902d263-8ef72.png"
        srcset="/static/commit-selector-bd72dec045515d59be51c944e902d263-69e48.png 210w,
/static/commit-selector-bd72dec045515d59be51c944e902d263-3b0aa.png 420w,
/static/commit-selector-bd72dec045515d59be51c944e902d263-8ef72.png 601w"
        sizes="(max-width: 601px) 100vw, 601px"
      />
    </span>
  </span>
  
  </a>
    </p>
<p>Each bar in the chart represents a single commit with the currently selected commit colored black.
You can click on a bar (or the left/right arrow buttons) to select a different commit.</p>
<p>The color and height of each bar corresponds to how long that commit took to render.
(Taller, yellow bars took longer than shorter, blue bars.)</p>
<h3 id="filtering-commits"><a href="#filtering-commits" aria-hidden="true" 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>Filtering commits </h3>
<p>The longer you profile, the more times your application will render.
In some cases you may end up with <em>too many commits</em> to easily process.
The profiler offers a filtering mechanism to help with this.
Use it to specify a threshold and the profiler will hide all commits that were <em>faster</em> than that value.</p>
<p><img src="/filtering-commits-683b9d860ef722e1505e5e629df7ef7e.gif" alt="Filtering commits by time"></p>
<h3 id="flame-chart"><a href="#flame-chart" aria-hidden="true" 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>Flame chart </h3>
<p>The flame chart view represents the state of your application for a particular commit.
Each bar in the chart represents a React component (e.g. <code class="gatsby-code-text">App</code>, <code class="gatsby-code-text">Nav</code>).
The size and color of the bar represents how long it took to render the component and its children.
(The width of a bar represents how much time was spent <em>when the component last rendered</em> and the color represents how much time was spent <em>as part of the current commit</em>.)</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/flame-chart-3046f500b9bfc052bde8b7b3b3cfc243-53c76.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 47.82608695652174%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAAB30lEQVQoz62Rz08TURDHG+O/xsW/gZeIN6M3L548kTSQiFHUgx5oS9PIqQkhgaIpEovYbep2d1vaQgndSpV2f++2XWRnZ3y7LejZ8E2+eW/mzXzevN1EZevdvaKwfV/6Xpuv1UQWWRRFJksSE4Qy2y0U2F6xyHZ3CqwiVJmi1Jksy6yuKHGNJEnzPF7gPXOJSMftZsccTejXQCdvNCLf92NPJhNyXIdc1yXDMkk3dZ5zyfMcnvfIdhzyxmMeexRJVVUxBrbaJ0dD3SVdMwJDN8EyLG4TTO7hQAOeB7V3Bu2zDvwY9MHqdeGnUIGLahV8bQgBwFUE1DStzHF3E5/yyaaw+ZSOS0k4+rKIjVISGwfPsbG3iKeHy9j6uoQdeR3HZh/9y4CvJqp1Bd3zcwwsCzkLIqBt20IMXN1aaz7cWKZn2+/DtdIH2hA/0mE1T0tvH9Cb9ceU//yKbN+ha0EY0u8guIkRMQZallWJgQenJ82dwQWVhkbYG1+iz2vkfhdf7m/ifquMmqNHU2CIfzXl3OgaOJ1w5HqN2WX8W/BDXgBIANOnwHSoEKLGyP/uZ76aAb/FQP6XunQLchxHiYHpdPpJNptdzWQyK9wv/sMrvP91KpV6FANnunMLTuRyucQfU2RSA7PakTgAAAAASUVORK5CYII='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="Example flame chart"
        title=""
        src="/static/flame-chart-3046f500b9bfc052bde8b7b3b3cfc243-acf85.png"
        srcset="/static/flame-chart-3046f500b9bfc052bde8b7b3b3cfc243-c1418.png 210w,
/static/flame-chart-3046f500b9bfc052bde8b7b3b3cfc243-5d5d8.png 420w,
/static/flame-chart-3046f500b9bfc052bde8b7b3b3cfc243-acf85.png 840w,
/static/flame-chart-3046f500b9bfc052bde8b7b3b3cfc243-53c76.png 1012w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<blockquote>
<p>Note:</p>
<p>The width of a bar indicates how long it took to render the component (and its children) when they last rendered.
If the component did not re-render as part of this commit, the time represents a previous render.
The wider a component is, the longer it took to render.</p>
<p>The color of a bar indicates how long the component (and its children) took to render in the selected commit.
Yellow components took more time, blue components took less time, and gray components did not render at all during this commit.</p>
</blockquote>
<p>For example, the commit shown above took a total of 18.4ms to render.
The <code class="gatsby-code-text">Router</code> component was the “most expensive” to render (taking 18.4ms).
Most of this time was due to two of its children, <code class="gatsby-code-text">Nav</code> (8.4ms) and <code class="gatsby-code-text">Route</code> (7.9ms).
The rest of the time was divided between its remaining children or spent in the component’s own render method.</p>
<p>You can zoom in or out on a flame chart by clicking on components:
<img src="/zoom-in-and-out-39ba82394205242af7c37ccb3a631f4d.gif" alt="Click on a component to zoom in or out"></p>
<p>Clicking on a component will also select it and show information in the right side panel which includes its <code class="gatsby-code-text">props</code> and <code class="gatsby-code-text">state</code> at the time of this commit.
You can drill into these to learn more about what the component actually rendered during the commit:</p>
<p><img src="/props-and-state-1f4d023f1a0f281386625f28df87c78f.gif" alt="Viewing a component&#x27;s props and state for a commit"></p>
<p>In some cases, selecting a component and stepping between commits may also provide a hint as to <em>why</em> the component rendered:</p>
<p><img src="/see-which-props-changed-cc2a8b37bbce52c49a11c2f8e55dccbc.gif" alt="Seeing which values changed between commits"></p>
<p>The above image shows that <code class="gatsby-code-text">state.scrollOffset</code> changed between commits.
This is likely what caused the <code class="gatsby-code-text">List</code> component to re-render.</p>
<h3 id="ranked-chart"><a href="#ranked-chart" aria-hidden="true" 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>Ranked chart </h3>
<p>The ranked chart view represents a single commit.
Each bar in the chart represents a React component (e.g. <code class="gatsby-code-text">App</code>, <code class="gatsby-code-text">Nav</code>).
The chart is ordered so that the components which took the longest to render are at the top.</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/ranked-chart-0c81347535e28c9cdef0e94fab887b89-53c76.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 47.82608695652174%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAABlUlEQVQoz62OT2/TMBiHI7SvxoXPMEtwhhvckPYBECqHIY6s6r/BdpjaXmARNzSta6WQpGuF1o5kW7e1YYmj1HHiuH6xvYpNOwBC+0mPbL2v9fxsdFrvHpn7zceHVnfV/tZFtnWNa/dQr/MVmbufkWl+QeanNuod7CHXsZHjuqjf7yPHcZBt26vyfGJZ1kND5Xg0HpEcwLskkKQcSAa/wXMOEY4hTa4giCgkdAFzQiGOMUQRhiRJNCq+71taOOhtD04HHwCPWwU7aXF22ubFEuo1eXb8kQuvxmf9TU7HW3wefOeTixmfTac8yzJeFAVTwiAIOlK3Yrwovx4+a7yClJxzYKEQWSAg/3kDuxIiDwUUob6nSSg8zxdRFAkpE9LFlRBjfKCFL3fqw72Jr2YLtf0TKly+IoQApRQYYyCE0EJZ0NXCtWZ9eEawFsqIf8ntnlvC6x/aP44Oc7FQM6aWf0OW3p2xpXBfC/OUenAPiePY1cL3GxvPq9XqeqVSKUne/AelWq32tlwuP9XCZR7cA0aj0TB+AdiMX66/MIlxAAAAAElFTkSuQmCC'); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="Example ranked chart"
        title=""
        src="/static/ranked-chart-0c81347535e28c9cdef0e94fab887b89-acf85.png"
        srcset="/static/ranked-chart-0c81347535e28c9cdef0e94fab887b89-c1418.png 210w,
/static/ranked-chart-0c81347535e28c9cdef0e94fab887b89-5d5d8.png 420w,
/static/ranked-chart-0c81347535e28c9cdef0e94fab887b89-acf85.png 840w,
/static/ranked-chart-0c81347535e28c9cdef0e94fab887b89-53c76.png 1012w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<blockquote>
<p>Note:</p>
<p>A component’s render time includes the time spent rendering its children,
so the components which took the longest to render are generally near the top of the tree.</p>
</blockquote>
<p>As with the flame chart, you can zoom in or out on a ranked chart by clicking on components.</p>
<h3 id="component-chart"><a href="#component-chart" aria-hidden="true" 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>Component chart </h3>
<p>Sometimes it’s useful to see how many times a particular component rendered while you were profiling.
The component chart provides this information in the form of a bar chart.
Each bar in the chart represents a time when the component rendered.
The color and height of each bar corresponds to how long the component took to render <em>relative to other components</em> in a particular commit.</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/component-chart-d71275b42c6109e222fbb0932a0c8c09-53c76.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 47.82608695652174%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAACSElEQVQoz62P20tUURTGh+gf6a33CHwTukCIQQ9JNw8kEZHRU2+9BzaCJ1LLB43xOPiaMjIgBl1Gzcuc0RnL0RQdTUWdOefsc3Wcs85ardlq9Af0wcf69tqL3147tjCeaPqiTzzM5xZbs9mscuJ5RWdPTU4qqVRKSafTyujIqJLJZBRd15WzuRzP5PP51kKh0JbL5a7H6lpZXloXrk27e/tkWhaZpkkWV0vYMpfLZVkNwyTTsEgIIV2f3auYZDsO1bW5WVqQwFJpa9lzHTosV0LX88D3ffC52lYFhLCAYbC/UwTXWOW8DfwY9wV4POP6Ac97NeGF9KO4Psu48zHnmIq00Ue1lV5AIqw7NJcwmH4sM0CEYRgihEfsABmEDMVqlc9RiCyob1gxjDkJrGwXipR/QrTWHdGZTJ0w00xQtfmAFNW8v1cRvxIeHpBrGVS2KuR6rgTaQsxLoFgdKdJCG1Vnn0bHYh0lwVlBmGjAo68tyE0Mph5hsPweg60xDJ0SVrd30d7ZQd8PMAKQQN76ZEN7bewnLbYTpC/Wqp+uwdGvBMBBBnDiMkSfGiCYeQ74uRFg/BKEqQsAvz9CzToGr7wPYSRhtVPgjAS6G+Ml2npJ9P0q0XwT0TTXmZtE2WaiuRucr5z09VucG4mcb0Q+f4S//K9s216SwMG+jhfJN+3dgx0tXVq8VR3qfKAOxe+o2ut77Luq1qmoWpxz/L6qddxWtb5Xav/bd2p/b4/6YWBAHdS0rmQy2ZNIJJ5J4KnO/QfHhoeHY38AsLpA6BTZFEwAAAAASUVORK5CYII='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="Example component chart"
        title=""
        src="/static/component-chart-d71275b42c6109e222fbb0932a0c8c09-acf85.png"
        srcset="/static/component-chart-d71275b42c6109e222fbb0932a0c8c09-c1418.png 210w,
/static/component-chart-d71275b42c6109e222fbb0932a0c8c09-5d5d8.png 420w,
/static/component-chart-d71275b42c6109e222fbb0932a0c8c09-acf85.png 840w,
/static/component-chart-d71275b42c6109e222fbb0932a0c8c09-53c76.png 1012w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<p>The chart above shows that the <code class="gatsby-code-text">List</code> component rendered 11 times.
It also shows that each time it rendered, it was the most “expensive” component in the commit (meaning that it took the longest).</p>
<p>To view this chart, either double-click on a component <em>or</em> select a component and click on the blue bar chart icon in the right detail pane.
You can return to the previous chart by clicking the “x” button in the right detail pane.
You can also double click on a particular bar to view more information about that commit.</p>
<p><img src="/see-all-commits-for-a-fiber-99cb4321ded8eb0c21ae5fc673878563.gif" alt="How to view all renders for a specific component"></p>
<p>If the selected component did not render at all during the profiling session, the following message will be shown:</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/no-render-times-for-selected-component-8eb0c37a13353ef5d9e61ae8fc040705-53c76.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 47.82608695652174%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAABZ0lEQVQoz62PzU7CQBDHG+OrefEZaKJnj74HHvQBCiHckQMx8eABE5VSUlDwQEI9oId+7PaD2rTLjrND26BHwz/5dbc7M/+Z0SZ3xumDdX9mT+yGaZp6xXg81ofDod7v9/XBYKD3erf4/0jvVY5ljnTbthvT6fTcsqwTTel9PlvyiMN6/QUBYxAEDBjbEQQBuK4Lvu+D53kE55xQuZ8egzCKQGm1ciZk6Dgf8zT9BtcPizhOxGazqUFTEUWRyPO8Bs2IJElETHlJzpMCXhfLZ7Q71jC4oBYghfrsU6m6qxMbSZxYZllWRreqTm3xQoZhGJLhFlUUBSiEEDXV286P8gAnpRjsOtEFBxv9MsSkLa4hFbiqZJxJjMk4jultX382IEOsqSd8KzvleAicQKRpSuBaKplQhQoVr+4leWn4RIY4gQMHEA42I8NWq3XZ6XSu2+12E7n6B02svzEM44IMSx0dAK3b7Wo/FtRnZY5UiRMAAAAASUVORK5CYII='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="No render times for the selected component"
        title=""
        src="/static/no-render-times-for-selected-component-8eb0c37a13353ef5d9e61ae8fc040705-acf85.png"
        srcset="/static/no-render-times-for-selected-component-8eb0c37a13353ef5d9e61ae8fc040705-c1418.png 210w,
/static/no-render-times-for-selected-component-8eb0c37a13353ef5d9e61ae8fc040705-5d5d8.png 420w,
/static/no-render-times-for-selected-component-8eb0c37a13353ef5d9e61ae8fc040705-acf85.png 840w,
/static/no-render-times-for-selected-component-8eb0c37a13353ef5d9e61ae8fc040705-53c76.png 1012w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<h3 id="interactions"><a href="#interactions" aria-hidden="true" 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>Interactions </h3>
<p>React recently added another <a href="https://fb.me/react-interaction-tracing" target="_blank" rel="nofollow noopener noreferrer">experimental API</a> for tracing the <em>cause</em> of an update.
“Interactions” traced with this API will also be shown in the profiler:</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/interactions-a91a39ac076b71aa7a202aaf46f8bd5a-53c76.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 47.82608695652174%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAABl0lEQVQoz62RzW7aQBDHraqvlkufIZaSc499j/TQPgAgxD1wQJFy6IFKSQyOgBAUKVFJJKAW9trOrm28O97J7ILpoT1VGemn9Xz9Z0Z2bi8an36MLk/G/vh4OBy6NaPRyB0MBm6v13P7/b7bPe+S/9PGPc+zNf7Qcyfj8fFkMjn1ff/IMfYwv3tMeIrL1RrjOEZG1C9jDDebDYZheCBJEkzT1ObXYYzJ6ysaWywWt1bw19PTPY8TXP2OVMA45FkGWY0QIASHoiggJwT5JAo0BMIogpAxE5Naa1wul9ck99F5mU7nIgiwoMIKkXKVNkZDNchSy0zossh1JaWNZ9tCr4JAx4zpPM9MCMyGdNWNFXyezeZpFCEPgkpVgGVZopTygFIKt0LYb07nizRGUW6RtseSYmS1oGcF4/V6jqaxKCoFoEEpDeYljK+sX+182pLut9vX/LVhyvkMd1m5n/Zvdo1AdSSvQf9B7gWvrCDnfIHvYPTnp1aw2Wx+abfb31qt1hnx9T84o/7vjUbjsxXc24d3wOl0Os4blShlbz/d1/8AAAAASUVORK5CYII='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="The interactions panel"
        title=""
        src="/static/interactions-a91a39ac076b71aa7a202aaf46f8bd5a-acf85.png"
        srcset="/static/interactions-a91a39ac076b71aa7a202aaf46f8bd5a-c1418.png 210w,
/static/interactions-a91a39ac076b71aa7a202aaf46f8bd5a-5d5d8.png 420w,
/static/interactions-a91a39ac076b71aa7a202aaf46f8bd5a-acf85.png 840w,
/static/interactions-a91a39ac076b71aa7a202aaf46f8bd5a-53c76.png 1012w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<p>The image above shows a profiling session that traced four interactions.
Each row represents an interaction that was traced.
The colored dots along the row represent commits that were related to that interaction.</p>
<p>You can also see which interactions were traced for a particular commit from the flame chart and ranked chart views as well:</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/interactions-for-commit-9847e78f930cb7cf2b0f9682853a5dbc-53c76.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 47.82608695652174%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAABuUlEQVQoz62Ry27aQBSGraqv1k2fISO16y77Humi3XUDCPECva3SICULLkkxYGKCsAmCFMYm2OBbYo7P6ZmBpllX+aVftmfO+fzPGaP97fPr0/aPN91f5pFpmkK50+mIbrcrms2GODn5Kc7PzsTXL99Fq9UW/X5f27Is0ev1VN0RP99yzytDaTS0x3dRSkt5R3GcUJZlj47jmDzPo9lsxt8xpWmq1zabDQVBQFEUaStNp9OOBlr29dV8uSYp5U56Hvi+r71arYBhwIUwHF6DlDNe8yAIQ/i9WIDHNdnDA+x2u1wBuafJuJdGvV637asBua4L4/EYlR3HRWswRNdx0HUnOJ/Pcb0OEAAwiSO8GY1wLSXmSYLMAgUMw7ClgXx2m+dBk8mk4DS8saEsjeiycUoXF5fkOA7luQ6hVdzfU3J7S9liQbnvExaFBvII2hrI87GTJFGzKbIs5X1CKlJMfROXS4k8N5UCH8Xv9MSsv8B9wu12Ozj8XMUAVcBdgPujwL+1vQtOhE+NmB+ADQ3kW7qhZxDffF8Dy+Xy+2q1+rFSqRyzP/yHj7n/U6lUeqeBB714Bhu1Ws34A880Xu+Ar3OjAAAAAElFTkSuQmCC'); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="List of interactions for a commit"
        title=""
        src="/static/interactions-for-commit-9847e78f930cb7cf2b0f9682853a5dbc-acf85.png"
        srcset="/static/interactions-for-commit-9847e78f930cb7cf2b0f9682853a5dbc-c1418.png 210w,
/static/interactions-for-commit-9847e78f930cb7cf2b0f9682853a5dbc-5d5d8.png 420w,
/static/interactions-for-commit-9847e78f930cb7cf2b0f9682853a5dbc-acf85.png 840w,
/static/interactions-for-commit-9847e78f930cb7cf2b0f9682853a5dbc-53c76.png 1012w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<p>You can navigate between interactions and commits by clicking on them:</p>
<p><img src="/navigate-between-interactions-and-commits-7c66e7686b5242473c87b3d0b4576cf3.gif" alt="Navigate between interactions and commits"></p>
<p>The tracing API is still new and we will cover it in more detail in a future blog post.</p>
<h2 id="troubleshooting"><a href="#troubleshooting" aria-hidden="true" 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>Troubleshooting </h2>
<h3 id="no-profiling-data-has-been-recorded-for-the-selected-root"><a href="#no-profiling-data-has-been-recorded-for-the-selected-root" aria-hidden="true" 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 profiling data has been recorded for the selected root </h3>
<p>If your application has multiple “roots”, you may see the following message after profiling:

  <a
    class="gatsby-resp-image-link"
    href="/static/no-profiler-data-multi-root-0755492a211f5bbb775285c0ff2fdfda-53c76.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 47.82608695652174%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAABjUlEQVQoz62Qy07CQBRAG+OvufEbmETXLv0PWOgH8GhY2wVCAjEuxbZUNEpMTCCB0kDoY0pfdKYz3hkeC40LE25yeqfzOHPnKtaDev74+ngxtIYlwzCQQNd11Ol0ULvdRpqmoftWC/V6PaTdaajb7SLTNOW+gaGjoWWVXoz+pTkwzxQRnwP9Cy8cbttz7vk+9zyP+5BXq5VkuVwexovFgruuywOxD3BcnwdBwHme8PFkbEnhZDT6yPyAu35Ioiimcbwl2ZMkh7xer2kURZQxRouioIQKaM4h4KI+6E6VIAxHfBsUYH8BHwYSyY81cU5U+iyFIcZSWGRZQaB8gvEvKMAJkbdCdRIQwxQRSCG0SZdCGEhhinERzGbMt20WAHg+Z6HjMG86ZWKeJAmD5x0qBBGD1rA0TffCbYXw9ndxU5KmebrZ0Ah6leW5RPzHcCDJMgrrsrciRA93TxXkO+GTFEKTJ/wIgTF+k8JarXbdaDRuIJfr9XoFckXkf1BWVfW2Wq1eSeEuTo6A0mw2lW+bPmTlyk2LHgAAAABJRU5ErkJggg=='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="No profiling data has been recorded for the selected root"
        title=""
        src="/static/no-profiler-data-multi-root-0755492a211f5bbb775285c0ff2fdfda-acf85.png"
        srcset="/static/no-profiler-data-multi-root-0755492a211f5bbb775285c0ff2fdfda-c1418.png 210w,
/static/no-profiler-data-multi-root-0755492a211f5bbb775285c0ff2fdfda-5d5d8.png 420w,
/static/no-profiler-data-multi-root-0755492a211f5bbb775285c0ff2fdfda-acf85.png 840w,
/static/no-profiler-data-multi-root-0755492a211f5bbb775285c0ff2fdfda-53c76.png 1012w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<p>This message indicates that no performance data was recorded for the root that’s selected in the “Elements” panel.
In this case, try selecting a different root in that panel to view profiling information for that root:</p>
<p><img src="/select-a-root-to-view-profiling-data-bdc30593d414b5c8d2ae92027ed11940.gif" alt="Select a root in the &#x22;Elements&#x22; panel to view its performance data"></p>
<h3 id="no-timing-data-to-display-for-the-selected-commit"><a href="#no-timing-data-to-display-for-the-selected-commit" aria-hidden="true" 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 timing data to display for the selected commit </h3>
<p>Sometimes a commit may be so fast that <code class="gatsby-code-text">performance.now()</code> doesn’t give DevTools any meaningful timing information.
In this case, the following message will be shown:</p>
<p>
  <a
    class="gatsby-resp-image-link"
    href="/static/no-timing-data-for-commit-63b2fb6298feecb179272c467020ed95-53c76.png"
    style="display: block"
    target="_blank"
    rel="noopener"
  >
  
  <span
    class="gatsby-resp-image-wrapper"
    style="position: relative; display: block;  max-width: 840px; margin-left: auto; margin-right: auto;"
  >
    <span
      class="gatsby-resp-image-background-image"
      style="padding-bottom: 47.82608695652174%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAABe0lEQVQoz61QTUvDQBAN4l/z4m9oQM8e/R/1oFehLaU/QSwWexK0CYQkrQURNGAxkKRJNh/tJpNdZzdJqSdB+uAxs7Ozb96Oot/dnj7q47OFaXZMy1RNs6Zt26quzdSHyVSdTJ/U8f1Y1TRd1i3LUufzuYzY28F4bhjGiSLwtrTfw4Twjy+PJ4TwLMt2jCLCw+Cbp4HD1+EaaylPkoTHcYx3kcwFBRzHMaSg7/uvDAtxRsuCUiiKAsqyhBLjZrMFmsdAExfCyAcoKaRpCqvVClzXxfuN6C2EoOd5Lyh3rBBClrwGINlfzPOcoRuGLllVVax5JxzPfgniFytsrr+bZ1zkguiIp/it7XZbTwXglFLegjEmBcMw1KRgEARLLHIUrkhCGJ4ZrmFHbGS4J0kc1rpie2gFa4doddFMLpCA0+Vu0J2MYqcoAi1ELkT2WDSCz1IQJ3/yAwB3akvBfr9/ORwOrweDQRd59Q928f1Nr9e7kIINjg5AZTQaKT+0smf7vT5VvwAAAABJRU5ErkJggg=='); background-size: cover; display: block;"
    >
      <img
        class="gatsby-resp-image-image"
        style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;"
        alt="No timing data to display for the selected commit"
        title=""
        src="/static/no-timing-data-for-commit-63b2fb6298feecb179272c467020ed95-acf85.png"
        srcset="/static/no-timing-data-for-commit-63b2fb6298feecb179272c467020ed95-c1418.png 210w,
/static/no-timing-data-for-commit-63b2fb6298feecb179272c467020ed95-5d5d8.png 420w,
/static/no-timing-data-for-commit-63b2fb6298feecb179272c467020ed95-acf85.png 840w,
/static/no-timing-data-for-commit-63b2fb6298feecb179272c467020ed95-53c76.png 1012w"
        sizes="(max-width: 840px) 100vw, 840px"
      />
    </span>
  </span>
  
  </a>
    </p>
<h2 id="deep-dive-video"><a href="#deep-dive-video" aria-hidden="true" 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>Deep dive video </h2>
<p>The following video demonstrates how the React profiler can be used to detect and improve performance bottlenecks in an actual React application.</p>
<br>
<div>
          <div
            class="gatsby-resp-iframe-wrapper"
            style="padding-bottom: 56.25%; position: relative; height: 0; overflow: hidden;"
          >
            <iframe src="https://www.youtube-nocookie.com/embed/nySib7ipZdk?rel=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen style="
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
          "></iframe>
          </div>
          </div>]]></description><link>https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html</link><guid isPermaLink="false">https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html</guid><pubDate>Mon, 10 Sep 2018 00:00:00 GMT</pubDate></item><item><title><![CDATA[React v16.4.2: Server-side vulnerability fix]]></title><description><![CDATA[<p>We discovered a minor vulnerability that might affect some apps using ReactDOMServer. We are releasing a patch version for every affected React minor release so that you can upgrade with no friction. Read on for more details.</p>
<h2 id="short-description"><a href="#short-description" aria-hidden="true" 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>Short Description </h2>
<p>Today, we are releasing a fix for a vulnerability we discovered in the <code class="gatsby-code-text">react-dom/server</code> implementation. It was introduced with the version 16.0.0 and has existed in all subsequent releases until today.</p>
<p>This vulnerability <strong>can only affect some server-rendered React apps.</strong> Purely client-rendered apps are <strong>not</strong> affected. Additionally, we expect that most server-rendered apps don’t contain the vulnerable pattern described below. Nevertheless, we recommend to follow the mitigation instructions at the earliest opportunity.</p>
<p>While we were investigating this vulnerability, we found similar vulnerabilities in a few other popular front-end libraries. We have coordinated this release together with <a href="https://github.com/vuejs/vue/releases/tag/v2.5.17" target="_blank" rel="nofollow noopener noreferrer">Vue</a> and <a href="https://github.com/developit/preact-render-to-string/releases/tag/3.7.1" target="_blank" rel="nofollow noopener noreferrer">Preact</a> releases fixing the same issue. The tracking number for this vulnerability is <code class="gatsby-code-text">CVE-2018-6341</code>.</p>
<h2 id="mitigation"><a href="#mitigation" aria-hidden="true" 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>Mitigation </h2>
<p><strong>We have prepared a patch release with a fix for every affected minor version.</strong></p>
<h3 id="160x"><a href="#160x" aria-hidden="true" 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>16.0.x </h3>
<p>If you’re using <code class="gatsby-code-text">react-dom/server</code> with this version:</p>
<ul>
<li><code class="gatsby-code-text">react-dom@16.0.0</code></li>
</ul>
<p>Update to this version instead:</p>
<ul>
<li><code class="gatsby-code-text">react-dom@16.0.1</code> <strong>(contains the mitigation)</strong></li>
</ul>
<h3 id="161x"><a href="#161x" aria-hidden="true" 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>16.1.x </h3>
<p>If you’re using <code class="gatsby-code-text">react-dom/server</code> with one of these versions:</p>
<ul>
<li><code class="gatsby-code-text">react-dom@16.1.0</code></li>
<li><code class="gatsby-code-text">react-dom@16.1.1</code></li>
</ul>
<p>Update to this version instead:</p>
<ul>
<li><code class="gatsby-code-text">react-dom@16.1.2</code> <strong>(contains the mitigation)</strong></li>
</ul>
<h3 id="162x"><a href="#162x" aria-hidden="true" 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>16.2.x </h3>
<p>If you’re using <code class="gatsby-code-text">react-dom/server</code> with this version:</p>
<ul>
<li><code class="gatsby-code-text">react-dom@16.2.0</code></li>
</ul>
<p>Update to this version instead:</p>
<ul>
<li><code class="gatsby-code-text">react-dom@16.2.1</code> <strong>(contains the mitigation)</strong></li>
</ul>
<h3 id="163x"><a href="#163x" aria-hidden="true" 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>16.3.x </h3>
<p>If you’re using <code class="gatsby-code-text">react-dom/server</code> with one of these versions:</p>
<ul>
<li><code class="gatsby-code-text">react-dom@16.3.0</code></li>
<li><code class="gatsby-code-text">react-dom@16.3.1</code></li>
<li><code class="gatsby-code-text">react-dom@16.3.2</code></li>
</ul>
<p>Update to this version instead:</p>
<ul>
<li><code class="gatsby-code-text">react-dom@16.3.3</code> <strong>(contains the mitigation)</strong></li>
</ul>
<h3 id="164x"><a href="#164x" aria-hidden="true" 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>16.4.x </h3>
<p>If you’re using <code class="gatsby-code-text">react-dom/server</code> with one of these versions:</p>
<ul>
<li><code class="gatsby-code-text">react-dom@16.4.0</code></li>
<li><code class="gatsby-code-text">react-dom@16.4.1</code></li>
</ul>
<p>Update to this version instead:</p>
<ul>
<li><code class="gatsby-code-text">react-dom@16.4.2</code> <strong>(contains the mitigation)</strong></li>
</ul>
<p>If you’re using a newer version of <code class="gatsby-code-text">react-dom</code>, no action is required.</p>
<p>Note that only the <code class="gatsby-code-text">react-dom</code> package needs to be updated.</p>
<h2 id="detailed-description"><a href="#detailed-description" aria-hidden="true" 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>Detailed Description </h2>
<p>Your app might be affected by this vulnerability only if both of these two conditions are true:</p>
<ul>
<li>Your app is <strong>being rendered to HTML using <a href="/docs/react-dom-server.html">ReactDOMServer API</a></strong>, and</li>
<li>Your app <strong>includes a user-supplied attribute name in an HTML tag.</strong></li>
</ul>
<p>Specifically, the vulnerable pattern looks like this:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">let</span> props <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="gatsby-highlight-code-line">props<span class="token punctuation">[</span>userProvidedData<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">"hello"</span><span class="token punctuation">;</span>
</span><span class="token keyword">let</span> element <span class="token operator">=</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token spread"><span class="token punctuation">{</span><span class="token punctuation">...</span><span class="token attr-value">props</span><span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">;</span>
<span class="token keyword">let</span> html <span class="token operator">=</span> ReactDOMServer<span class="token punctuation">.</span><span class="token function">renderToString</span><span class="token punctuation">(</span>element<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
<p>In order to exploit it, the attacker would need to craft a special attribute name that triggers an <a href="https://en.wikipedia.org/wiki/Cross-site_scripting" target="_blank" rel="nofollow noopener noreferrer">XSS</a> vulnerability. For example:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">let</span> userProvidedData <span class="token operator">=</span> <span class="token string">'>&lt;/div>&lt;script>alert("hi")&lt;/script>'</span><span class="token punctuation">;</span></code></pre></div>
<p>In the vulnerable versions of <code class="gatsby-code-text">react-dom/server</code>, the output would let the attacker inject arbitrary markup:</p>
<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>div</span> <span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">></span></span><span class="token script language-javascript"><span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">"hi"</span><span class="token punctuation">)</span></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>
<p>In the versions after the vulnerability was <a href="https://github.com/facebook/react/pull/13302" target="_blank" rel="nofollow noopener noreferrer">fixed</a> (and before it was introduced), attributes with invalid names are skipped:</p>
<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>div</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span></code></pre></div>
<p>You would also see a warning about an invalid attribute name.</p>
<p>Note that <strong>we expect attribute names based on user input to be very rare in practice.</strong> It doesn’t serve any common practical use case, and has other potential security implications that React can’t guard against.</p>
<h2 id="installation"><a href="#installation" aria-hidden="true" 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>
<p>React v16.4.2 is available on the npm registry.</p>
<p>To install React 16 with Yarn, run:</p>
<div class="gatsby-highlight" data-language="bash"><pre class="gatsby-code-bash"><code class="gatsby-code-bash">yarn add react@^16.4.2 react-dom@^16.4.2</code></pre></div>
<p>To install React 16 with npm, run:</p>
<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.4.2 react-dom@^16.4.2</code></pre></div>
<p>We also provide UMD builds of React via a CDN:</p>
<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">=</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 language-javascript"></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">></span></span>
<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">=</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 language-javascript"></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>
<p>Refer to the documentation for <a href="/docs/installation.html">detailed installation instructions</a>.</p>
<h2 id="changelog"><a href="#changelog" aria-hidden="true" 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>
<h3 id="react-dom-server"><a href="#react-dom-server" aria-hidden="true" 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 Server </h3>
<ul>
<li>
<p>Fix a potential XSS vulnerability when the attacker controls an attribute name (<code class="gatsby-code-text">CVE-2018-6341</code>). This fix is available in the latest <code class="gatsby-code-text">react-dom@16.4.2</code>, as well as in previous affected minor versions: <code class="gatsby-code-text">react-dom@16.0.1</code>, <code class="gatsby-code-text">react-dom@16.1.2</code>, <code class="gatsby-code-text">react-dom@16.2.1</code>, and <code class="gatsby-code-text">react-dom@16.3.3</code>. (<a href="https://github.com/gaearon" target="_blank" rel="nofollow noopener noreferrer">@gaearon</a> in <a href="https://github.com/facebook/react/pull/13302" target="_blank" rel="nofollow noopener noreferrer">#13302</a>)</p>
</li>
<li>
<p>Fix a crash in the server renderer when an attribute is called <code class="gatsby-code-text">hasOwnProperty</code>. This fix is only available in <code class="gatsby-code-text">react-dom@16.4.2</code>. (<a href="https://github.com/gaearon" target="_blank" rel="nofollow noopener noreferrer">@gaearon</a> in <a href="https://github.com/facebook/react/pull/13303" target="_blank" rel="nofollow noopener noreferrer">#13303</a>)</p>
</li>
</ul>]]></description><link>https://reactjs.org/blog/2018/08/01/react-v-16-4-2.html</link><guid isPermaLink="false">https://reactjs.org/blog/2018/08/01/react-v-16-4-2.html</guid><pubDate>Wed, 01 Aug 2018 00:00:00 GMT</pubDate></item><item><title><![CDATA[You Probably Don't Need Derived State]]></title><description><![CDATA[<p>React 16.4 included a <a href="/blog/2018/05/23/react-v-16-4.html#bugfix-for-getderivedstatefromprops">bugfix for getDerivedStateFromProps</a> which caused some existing bugs in React components to reproduce more consistently. If this release exposed a case where your application was using an anti-pattern and didn’t work properly after the fix, we’re sorry for the churn. In this post, we will explain some common anti-patterns with derived state and our preferred alternatives.</p>
<p>For a long time, the lifecycle <code class="gatsby-code-text">componentWillReceiveProps</code> was the only way to update state in response to a change in props without an additional render. In version 16.3, <a href="/blog/2018/03/29/react-v-16-3.html#component-lifecycle-changes">we introduced a replacement lifecycle, <code class="gatsby-code-text">getDerivedStateFromProps</code></a> to solve the same use cases in a safer way. At the same time, we’ve realized that people have many misconceptions about how to use both methods, and we’ve found anti-patterns that result in subtle and confusing bugs. The <code class="gatsby-code-text">getDerivedStateFromProps</code> bugfix in 16.4 <a href="https://github.com/facebook/react/issues/12898" target="_blank" rel="nofollow noopener noreferrer">makes derived state more predictable</a>, so the results of misusing it are easier to notice.</p>
<blockquote>
<p>Note</p>
<p>All of the anti-patterns described in this post apply to both the older <code class="gatsby-code-text">componentWillReceiveProps</code> and the newer <code class="gatsby-code-text">getDerivedStateFromProps</code>.</p>
</blockquote>
<p> This blog post will cover the following topics:</p>
<ul>
<li><a href="#when-to-use-derived-state">When to use derived state</a></li>
<li>
<p><a href="#common-bugs-when-using-derived-state">Common bugs when using derived state</a></p>
<ul>
<li><a href="#anti-pattern-unconditionally-copying-props-to-state">Anti-pattern: Unconditionally copying props to state</a></li>
<li><a href="#anti-pattern-erasing-state-when-props-change">Anti-pattern: Erasing state when props change</a></li>
</ul>
</li>
<li><a href="#preferred-solutions">Preferred solutions</a></li>
<li><a href="#what-about-memoization">What about memoization?</a></li>
</ul>
<h2 id="when-to-use-derived-state"><a href="#when-to-use-derived-state" aria-hidden="true" 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>When to Use Derived State </h2>
<p><code class="gatsby-code-text">getDerivedStateFromProps</code> exists for only one purpose. It enables a component to update its internal state as the result of <strong>changes in props</strong>. Our previous blog post provided some examples, like <a href="/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props">recording the current scroll direction based on a changing offset prop</a> or <a href="/blog/2018/03/27/update-on-async-rendering.html#fetching-external-data-when-props-change">loading external data specified by a source prop</a>.</p>
<p>We did not provide many examples, because as a general rule, <strong>derived state should be used sparingly</strong>. All problems with derived state that we have seen can be ultimately reduced to either (1) unconditionally updating state from props or (2) updating state whenever props and state don’t match. (We’ll go over both in more detail below.)</p>
<ul>
<li>If you’re using derived state to memoize some computation based only on the current props, you don’t need derived state. See <a href="#what-about-memoization">What about memoization?</a> below.</li>
<li>If you’re updating derived state unconditionally or updating it whenever props and state don’t match, your component likely resets its state too frequently. Read on for more details.</li>
</ul>
<h2 id="common-bugs-when-using-derived-state"><a href="#common-bugs-when-using-derived-state" aria-hidden="true" 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>Common Bugs When Using Derived State </h2>
<p>The terms <a href="/docs/forms.html#controlled-components">“controlled”</a> and <a href="/docs/uncontrolled-components.html">“uncontrolled”</a> usually refer to form inputs, but they can also describe where any component’s data lives. Data passed in as props can be thought of as <strong>controlled</strong> (because the parent component <em>controls</em> that data). Data that exists only in internal state can be thought of as <strong>uncontrolled</strong> (because the parent can’t directly change it).</p>
<p>The most common mistake with derived state is mixing these two; when a derived state value is also updated by <code class="gatsby-code-text">setState</code> calls, there isn’t a single source of truth for the data. The <a href="/blog/2018/03/27/update-on-async-rendering.html#fetching-external-data-when-props-change">external data loading example</a> mentioned above may sound similar, but it’s different in a few important ways. In the loading example, there is a clear source of truth for both the “source” prop and the “loading” state. When the source prop changes, the loading state should <strong>always</strong> be overridden. Conversely, the state is overridden only when the prop <strong>changes</strong> and is otherwise managed by the component.</p>
<p>Problems arise when any of these constraints are changed. This typically comes in two forms. Let’s take a look at both.</p>
<h3 id="anti-pattern-unconditionally-copying-props-to-state"><a href="#anti-pattern-unconditionally-copying-props-to-state" aria-hidden="true" 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>Anti-pattern: Unconditionally copying props to state </h3>
<p>A common misconception is that <code class="gatsby-code-text">getDerivedStateFromProps</code> and <code class="gatsby-code-text">componentWillReceiveProps</code> are only called when props “change”. These lifecycles are called any time a parent component rerenders, regardless of whether the props are “different” from before. Because of this, it has always been unsafe to <em>unconditionally</em> override state using either of these lifecycles. <strong>Doing so will cause state updates to be lost.</strong></p>
<p>Let’s consider an example to demonstrate the problem. Here is a <code class="gatsby-code-text">EmailInput</code> component that “mirrors” an email prop in state:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">class</span> <span class="token class-name">EmailInput</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  state <span class="token operator">=</span> <span class="token punctuation">{</span> email<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>email <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>handleChange<span class="token punctuation">}</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>email<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token function-variable function">handleChange</span> <span class="token operator">=</span> event <span class="token operator">=></span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> email<span class="token punctuation">:</span> event<span class="token punctuation">.</span>target<span class="token punctuation">.</span>value <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token function">componentWillReceiveProps</span><span class="token punctuation">(</span>nextProps<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// This will erase any local state updates!</span>
    <span class="token comment">// Do not do this.</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> email<span class="token punctuation">:</span> nextProps<span class="token punctuation">.</span>email <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>At first, this component might look okay. State is initialized to the value specified by props and updated when we type into the <code class="gatsby-code-text">&lt;input&gt;</code>. But if our component’s parent rerenders, anything we’ve typed into the <code class="gatsby-code-text">&lt;input&gt;</code> will be lost! (<a href="https://codesandbox.io/s/m3w9zn1z8x" target="_blank" rel="nofollow noopener noreferrer">See this demo for an example.</a>) This holds true even if we were to compare <code class="gatsby-code-text">nextProps.email !== this.state.email</code> before resetting.</p>
<p>In this simple example, adding <code class="gatsby-code-text">shouldComponentUpdate</code> to rerender only when the email prop has changed could fix this. However in practice, components usually accept multiple props; another prop changing would still cause a rerender and improper reset. Function and object props are also often created inline, making it hard to implement a <code class="gatsby-code-text">shouldComponentUpdate</code> that reliably returns true only when a material change has happened. <a href="https://codesandbox.io/s/jl0w6r9w59" target="_blank" rel="nofollow noopener noreferrer">Here is a demo that shows that happening.</a> As a result, <code class="gatsby-code-text">shouldComponentUpdate</code> is best used as a performance optimization, not to ensure correctness of derived state.</p>
<p>Hopefully it’s clear by now why <strong>it is a bad idea to unconditionally copy props to state</strong>. Before reviewing possible solutions, let’s look at a related problematic pattern: what if we were to only update the state when the email prop changes?</p>
<h3 id="anti-pattern-erasing-state-when-props-change"><a href="#anti-pattern-erasing-state-when-props-change" aria-hidden="true" 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>Anti-pattern: Erasing state when props change </h3>
<p>Continuing the example above, we could avoid accidentally erasing state by only updating it when <code class="gatsby-code-text">props.email</code> changes:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">class</span> <span class="token class-name">EmailInput</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  state <span class="token operator">=</span> <span class="token punctuation">{</span>
    email<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>email
  <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token function">componentWillReceiveProps</span><span class="token punctuation">(</span>nextProps<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// Any time props.email changes, update state.</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>nextProps<span class="token punctuation">.</span>email <span class="token operator">!==</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>email<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
        email<span class="token punctuation">:</span> nextProps<span class="token punctuation">.</span>email
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
  
  <span class="token comment">// ...</span>
<span class="token punctuation">}</span></code></pre></div>
<blockquote>
<p>Note</p>
<p>Even though the example above shows <code class="gatsby-code-text">componentWillReceiveProps</code>, the same anti-pattern applies to <code class="gatsby-code-text">getDerivedStateFromProps</code>.</p>
</blockquote>
<p>We’ve just made a big improvement. Now our component will erase what we’ve typed only when the props actually change.</p>
<p>There is still a subtle problem. Imagine a password manager app using the above input component. When navigating between details for two accounts with the same email, the input would fail to reset. This is because the prop value passed to the component would be the same for both accounts! This would be a surprise to the user, as an unsaved change to one account would appear to affect other accounts that happened to share the same email. (<a href="https://codesandbox.io/s/mz2lnkjkrx" target="_blank" rel="nofollow noopener noreferrer">See demo here.</a>)</p>
<p>This design is fundamentally flawed, but it’s also an easy mistake to make. (<a href="https://twitter.com/brian_d_vaughn/status/959600888242307072" target="_blank" rel="nofollow noopener noreferrer">I’ve made it myself!</a>) Fortunately there are two alternatives that work better. The key to both is that <strong>for any piece of data, you need to pick a single component that owns it as the source of truth, and avoid duplicating it in other components.</strong> Let’s take a look at each of the alternatives.</p>
<h2 id="preferred-solutions"><a href="#preferred-solutions" aria-hidden="true" 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>Preferred Solutions </h2>
<h3 id="recommendation-fully-controlled-component"><a href="#recommendation-fully-controlled-component" aria-hidden="true" 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>Recommendation: Fully controlled component </h3>
<p>One way to avoid the problems mentioned above is to remove state from our component entirely. If the email address only exists as a prop, then we don’t have to worry about conflicts with state. We could even convert <code class="gatsby-code-text">EmailInput</code> to a lighter-weight function component:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">function</span> <span class="token function">EmailInput</span><span class="token punctuation">(</span>props<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>props<span class="token punctuation">.</span>onChange<span class="token punctuation">}</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>props<span class="token punctuation">.</span>email<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This approach simplifies the implementation of our component, but if we still want to store a draft value, the parent form component will now need to do that manually. (<a href="https://codesandbox.io/s/7154w1l551" target="_blank" rel="nofollow noopener noreferrer">Click here to see a demo of this pattern.</a>)</p>
<h3 id="recommendation-fully-uncontrolled-component-with-a-key"><a href="#recommendation-fully-uncontrolled-component-with-a-key" aria-hidden="true" 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>Recommendation: Fully uncontrolled component with a <code class="gatsby-code-text">key</code> </h3>
<p>Another alternative would be for our component to fully own the “draft” email state. In that case, our component could still accept a prop for the <em>initial</em> value, but it would ignore subsequent changes to that prop:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">class</span> <span class="token class-name">EmailInput</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  state <span class="token operator">=</span> <span class="token punctuation">{</span> email<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>defaultEmail <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token function-variable function">handleChange</span> <span class="token operator">=</span> event <span class="token operator">=></span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> email<span class="token punctuation">:</span> event<span class="token punctuation">.</span>target<span class="token punctuation">.</span>value <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>handleChange<span class="token punctuation">}</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>email<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>In order to reset the value when moving to a different item (as in our password manager scenario), we can use the special React attribute called <code class="gatsby-code-text">key</code>. When a <code class="gatsby-code-text">key</code> changes, React will <a href="/docs/reconciliation.html#keys"><em>create</em> a new component instance rather than <em>update</em> the current one</a>. Keys are usually used for dynamic lists but are also useful here. In our case, we could use the user ID to recreate the email input any time a new user is selected:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>EmailInput</span>
  <span class="token attr-name">defaultEmail</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>user<span class="token punctuation">.</span>email<span class="token punctuation">}</span></span>
  <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>user<span class="token punctuation">.</span>id<span class="token punctuation">}</span></span>
<span class="token punctuation">/></span></span></code></pre></div>
<p>Each time the ID changes, the <code class="gatsby-code-text">EmailInput</code> will be recreated and its state will be reset to the latest <code class="gatsby-code-text">defaultEmail</code> value. (<a href="https://codesandbox.io/s/6v1znlxyxn" target="_blank" rel="nofollow noopener noreferrer">Click here to see a demo of this pattern.</a>) With this approach, you don’t have to add <code class="gatsby-code-text">key</code> to every input. It might make more sense to put a <code class="gatsby-code-text">key</code> on the whole form instead. Every time the key changes, all components within the form will be recreated with a freshly initialized state.</p>
<p>In most cases, this is the best way to handle state that needs to be reset.</p>
<blockquote>
<p>Note</p>
<p>While this may sound slow, the performance difference is usually insignificant. Using a key can even be faster if the components have heavy logic that runs on updates since diffing gets bypassed for that subtree.</p>
</blockquote>
<h4 id="alternative-1-reset-uncontrolled-component-with-an-id-prop"><a href="#alternative-1-reset-uncontrolled-component-with-an-id-prop" aria-hidden="true" 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>Alternative 1: Reset uncontrolled component with an ID prop </h4>
<p>If <code class="gatsby-code-text">key</code> doesn’t work for some reason (perhaps the component is very expensive to initialize), a workable but cumbersome solution would be to watch for changes to “userID” in <code class="gatsby-code-text">getDerivedStateFromProps</code>:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">class</span> <span class="token class-name">EmailInput</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  state <span class="token operator">=</span> <span class="token punctuation">{</span>
    email<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>defaultEmail<span class="token punctuation">,</span>
    prevPropsUserID<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>userID
  <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token keyword">static</span> <span class="token function">getDerivedStateFromProps</span><span class="token punctuation">(</span>props<span class="token punctuation">,</span> state<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// Any time the current user changes,</span>
    <span class="token comment">// Reset any parts of state that are tied to that user.</span>
    <span class="token comment">// In this simple example, that's just the email.</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>props<span class="token punctuation">.</span>userID <span class="token operator">!==</span> state<span class="token punctuation">.</span>prevPropsUserID<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token punctuation">{</span>
        prevPropsUserID<span class="token punctuation">:</span> props<span class="token punctuation">.</span>userID<span class="token punctuation">,</span>
        email<span class="token punctuation">:</span> props<span class="token punctuation">.</span>defaultEmail
      <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// ...</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This also provides the flexibility to only reset parts of our component’s internal state if we so choose. (<a href="https://codesandbox.io/s/rjyvp7l3rq" target="_blank" rel="nofollow noopener noreferrer">Click here to see a demo of this pattern.</a>)</p>
<blockquote>
<p>Note</p>
<p>Even though the example above shows <code class="gatsby-code-text">getDerivedStateFromProps</code>, the same technique can be used with <code class="gatsby-code-text">componentWillReceiveProps</code>.</p>
</blockquote>
<h4 id="alternative-2-reset-uncontrolled-component-with-an-instance-method"><a href="#alternative-2-reset-uncontrolled-component-with-an-instance-method" aria-hidden="true" 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>Alternative 2: Reset uncontrolled component with an instance method </h4>
<p>More rarely, you may need to reset state even if there’s no appropriate ID to use as <code class="gatsby-code-text">key</code>. One solution is to reset the key to a random value or autoincrementing number each time you want to reset. One other viable alternative is to expose an instance method to imperatively reset the internal state:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">class</span> <span class="token class-name">EmailInput</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  state <span class="token operator">=</span> <span class="token punctuation">{</span>
    email<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>defaultEmail
  <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token function">resetEmailForNewUser</span><span class="token punctuation">(</span>newEmail<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> email<span class="token punctuation">:</span> newEmail <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// ...</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The parent form component could then <a href="/docs/glossary.html#refs">use a <code class="gatsby-code-text">ref</code> to call this method</a>. (<a href="https://codesandbox.io/s/l70krvpykl" target="_blank" rel="nofollow noopener noreferrer">Click here to see a demo of this pattern.</a>)</p>
<p>Refs can be useful in certain cases like this one, but generally we recommend you use them sparingly. Even in the demo, this imperative method is nonideal because two renders will occur instead of one.</p>
<hr>
<h3 id="recap"><a href="#recap" aria-hidden="true" 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>Recap </h3>
<p>To recap, when designing a component, it is important to decide whether its data will be controlled or uncontrolled.</p>
<p>Instead of trying to <strong>“mirror” a prop value in state</strong>, make the component <strong>controlled</strong>, and consolidate the two diverging values in the state of some parent component. For example, rather than a child accepting a “committed” <code class="gatsby-code-text">props.value</code> and tracking a “draft” <code class="gatsby-code-text">state.value</code>, have the parent manage both <code class="gatsby-code-text">state.draftValue</code> and <code class="gatsby-code-text">state.committedValue</code> and control the child’s value directly. This makes the data flow more explicit and predictable.</p>
<p>For <strong>uncontrolled</strong> components, if you’re trying to reset state when a particular prop (usually an ID) changes, you have a few options:</p>
<ul>
<li><strong>Recommendation: To reset <em>all internal state</em>, use the <code class="gatsby-code-text">key</code> attribute.</strong></li>
<li>Alternative 1: To reset <em>only certain state fields</em>, watch for changes in a special property (e.g. <code class="gatsby-code-text">props.userID</code>).</li>
<li>Alternative 2: You can also consider fall back to an imperative instance method using refs.</li>
</ul>
<h2 id="what-about-memoization"><a href="#what-about-memoization" aria-hidden="true" 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 about memoization? </h2>
<p>We’ve also seen derived state used to ensure an expensive value used in <code class="gatsby-code-text">render</code> is recomputed only when the inputs change. This technique is known as <a href="https://en.wikipedia.org/wiki/Memoization" target="_blank" rel="nofollow noopener noreferrer">memoization</a>.</p>
<p>Using derived state for memoization isn’t necessarily bad, but it’s usually not the best solution. There is inherent complexity in managing derived state, and this complexity increases with each additional property. For example, if we add a second derived field to our component state then our implementation would need to separately track changes to both.</p>
<p>Let’s look at an example of one component that takes one prop—a list of items—and renders the items that match a search query entered by the user. We could use derived state to store the filtered list:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">class</span> <span class="token class-name">Example</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  state <span class="token operator">=</span> <span class="token punctuation">{</span>
    filterText<span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token comment">// *******************************************************</span>
  <span class="token comment">// NOTE: this example is NOT the recommended approach.</span>
  <span class="token comment">// See the examples below for our recommendations instead.</span>
  <span class="token comment">// *******************************************************</span>

  <span class="token keyword">static</span> <span class="token function">getDerivedStateFromProps</span><span class="token punctuation">(</span>props<span class="token punctuation">,</span> state<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// Re-run the filter whenever the list array or filter text change.</span>
    <span class="token comment">// Note we need to store prevPropsList and prevFilterText to detect changes.</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>
      props<span class="token punctuation">.</span>list <span class="token operator">!==</span> state<span class="token punctuation">.</span>prevPropsList <span class="token operator">||</span>
      state<span class="token punctuation">.</span>prevFilterText <span class="token operator">!==</span> state<span class="token punctuation">.</span>filterText
    <span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token punctuation">{</span>
        prevPropsList<span class="token punctuation">:</span> props<span class="token punctuation">.</span>list<span class="token punctuation">,</span>
        prevFilterText<span class="token punctuation">:</span> state<span class="token punctuation">.</span>filterText<span class="token punctuation">,</span>
        filteredList<span class="token punctuation">:</span> props<span class="token punctuation">.</span>list<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>item <span class="token operator">=></span> item<span class="token punctuation">.</span>text<span class="token punctuation">.</span><span class="token function">includes</span><span class="token punctuation">(</span>state<span class="token punctuation">.</span>filterText<span class="token punctuation">)</span><span class="token punctuation">)</span>
      <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token function-variable function">handleChange</span> <span class="token operator">=</span> event <span class="token operator">=></span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> filterText<span class="token punctuation">:</span> event<span class="token punctuation">.</span>target<span class="token punctuation">.</span>value <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">(</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Fragment</span><span class="token punctuation">></span></span><span class="token plain-text">
        </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>handleChange<span class="token punctuation">}</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>filterText<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span><span class="token plain-text">
        </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ul</span><span class="token punctuation">></span></span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>filteredList<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>item <span class="token operator">=></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>item<span class="token punctuation">.</span>id<span class="token punctuation">}</span></span><span class="token punctuation">></span></span><span class="token punctuation">{</span>item<span class="token punctuation">.</span>text<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span class="token punctuation">></span></span><span class="token plain-text">
      </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Fragment</span><span class="token punctuation">></span></span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This implementation avoids recalculating <code class="gatsby-code-text">filteredList</code> more often than necessary. But it is more complicated than it needs to be, because it has to separately track and detect changes in both props and state in order to properly update the filtered list. In this example, we could simplify things by using <code class="gatsby-code-text">PureComponent</code> and moving the filter operation into the render method: </p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token comment">// PureComponents only rerender if at least one state or prop value changes.</span>
<span class="token comment">// Change is determined by doing a shallow comparison of state and prop keys.</span>
<span class="token keyword">class</span> <span class="token class-name">Example</span> <span class="token keyword">extends</span> <span class="token class-name">PureComponent</span> <span class="token punctuation">{</span>
  <span class="token comment">// State only needs to hold the current filter text value:</span>
  state <span class="token operator">=</span> <span class="token punctuation">{</span>
    filterText<span class="token punctuation">:</span> <span class="token string">""</span>
  <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token function-variable function">handleChange</span> <span class="token operator">=</span> event <span class="token operator">=></span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> filterText<span class="token punctuation">:</span> event<span class="token punctuation">.</span>target<span class="token punctuation">.</span>value <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// The render method on this PureComponent is called only if</span>
    <span class="token comment">// props.list or state.filterText has changed.</span>
    <span class="token keyword">const</span> filteredList <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>list<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>
      item <span class="token operator">=></span> item<span class="token punctuation">.</span>text<span class="token punctuation">.</span><span class="token function">includes</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>filterText<span class="token punctuation">)</span>
    <span class="token punctuation">)</span>

    <span class="token keyword">return</span> <span class="token punctuation">(</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Fragment</span><span class="token punctuation">></span></span><span class="token plain-text">
        </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>handleChange<span class="token punctuation">}</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>filterText<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span><span class="token plain-text">
        </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ul</span><span class="token punctuation">></span></span><span class="token punctuation">{</span>filteredList<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>item <span class="token operator">=></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>item<span class="token punctuation">.</span>id<span class="token punctuation">}</span></span><span class="token punctuation">></span></span><span class="token punctuation">{</span>item<span class="token punctuation">.</span>text<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span class="token punctuation">></span></span><span class="token plain-text">
      </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Fragment</span><span class="token punctuation">></span></span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>The above approach is much cleaner and simpler than the derived state version. Occasionally, this won’t be good enough—filtering may be slow for large lists, and <code class="gatsby-code-text">PureComponent</code> won’t prevent rerenders if another prop were to change. To address both of these concerns, we could add a memoization helper to avoid unnecessarily re-filtering our list:</p>
<div class="gatsby-highlight" data-language="jsx"><pre class="gatsby-code-jsx"><code class="gatsby-code-jsx"><span class="token keyword">import</span> memoize <span class="token keyword">from</span> <span class="token string">"memoize-one"</span><span class="token punctuation">;</span>

<span class="token keyword">class</span> <span class="token class-name">Example</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>
  <span class="token comment">// State only needs to hold the current filter text value:</span>
  state <span class="token operator">=</span> <span class="token punctuation">{</span> filterText<span class="token punctuation">:</span> <span class="token string">""</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token comment">// Re-run the filter whenever the list array or filter text changes:</span>
  filter <span class="token operator">=</span> <span class="token function">memoize</span><span class="token punctuation">(</span>
    <span class="token punctuation">(</span>list<span class="token punctuation">,</span> filterText<span class="token punctuation">)</span> <span class="token operator">=></span> list<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span>item <span class="token operator">=></span> item<span class="token punctuation">.</span>text<span class="token punctuation">.</span><span class="token function">includes</span><span class="token punctuation">(</span>filterText<span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token function-variable function">handleChange</span> <span class="token operator">=</span> event <span class="token operator">=></span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> filterText<span class="token punctuation">:</span> event<span class="token punctuation">.</span>target<span class="token punctuation">.</span>value <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">;</span>

  <span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// Calculate the latest filtered list. If these arguments haven't changed</span>
    <span class="token comment">// since the last render, `memoize-one` will reuse the last return value.</span>
    <span class="token keyword">const</span> filteredList <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>props<span class="token punctuation">.</span>list<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>filterText<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">return</span> <span class="token punctuation">(</span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Fragment</span><span class="token punctuation">></span></span><span class="token plain-text">
        </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>handleChange<span class="token punctuation">}</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>filterText<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span><span class="token plain-text">
        </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ul</span><span class="token punctuation">></span></span><span class="token punctuation">{</span>filteredList<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span>item <span class="token operator">=></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>li</span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>item<span class="token punctuation">.</span>id<span class="token punctuation">}</span></span><span class="token punctuation">></span></span><span class="token punctuation">{</span>item<span class="token punctuation">.</span>text<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>li</span><span class="token punctuation">></span></span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>ul</span><span class="token punctuation">></span></span><span class="token plain-text">
      </span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Fragment</span><span class="token punctuation">></span></span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre></div>
<p>This is much simpler and performs just as well as the derived state version!</p>
<p>When using memoization, remember a couple of constraints:</p>
<ol>
<li>In most cases, you’ll want to <strong>attach the memoized function to a component instance</strong>. This prevents multiple instances of a component from resetting each other’s memoized keys.</li>
<li>Typically you’ll want to use a memoization helper with a <strong>limited cache size</strong> in order to prevent memory leaks over time. (In the example above, we used <code class="gatsby-code-text">memoize-one</code> because it only caches the most recent arguments and result.)</li>
<li>None of the implementations shown in this section will work if <code class="gatsby-code-text">props.list</code> is recreated each time the parent component renders. But in most cases, this setup is appropriate.</li>
</ol>
<h2 id="in-closing"><a href="#in-closing" aria-hidden="true" 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>In closing </h2>
<p>In real world applications, components often contain a mix of controlled and uncontrolled behaviors. This is okay! If each value has a clear source of truth, you can avoid the anti-patterns mentioned above.</p>
<p>It is also worth re-iterating that <code class="gatsby-code-text">getDerivedStateFromProps</code> (and derived state in general) is an advanced feature and should be used sparingly because of this complexity. If your use case falls outside of these patterns, please share it with us on <a href="https://github.com/reactjs/reactjs.org/issues/new" target="_blank" rel="nofollow noopener noreferrer">GitHub</a> or <a href="https://twitter.com/reactjs" target="_blank" rel="nofollow noopener noreferrer">Twitter</a>!</p>]]></description><link>https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html</link><guid isPermaLink="false">https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html</guid><pubDate>Thu, 07 Jun 2018 00:00:00 GMT</pubDate></item></channel></rss>