Today we release React 17! We have been writing for a long time about the role of React 17 and the changes it contains React 17 RC blog post. This message is a brief summary of it, so if you have already read the RC message, you can skip this.
React 17 is unusual in that it does not add new features for developers. Instead, this publication focuses primarily on which makes it easier to update React itself.
In particular, React 17 is a “stepping stone” release that makes it safer to immerse a tree controlled by one version of React inside a tree managed by a different version of React.
It also makes it easier to embed React in applications built on other technologies.
React 17 allows for a gradual React upgrade. When you upgrade from React 15 to 16 (or this time from React 16 to 17), you usually upgrade your entire app at once. This works well in many applications. But it can be even more challenging if the code template was written more than a few years ago and is not actively maintained. And while it is possible to use two versions of React on the page, until reaction 17 it has been fragile and has caused problems with events.
We will fix many of these issues with React 17. this means that when React 18 and subsequent upcoming versions appear, you now have more options. The first option is to update your entire application at once, as you may have done before. But you also have the option to update your app piece by piece. For example, you might decide to move most of your application to React 18, but keep some lazy downloaded dialog box or subroutine in React 17.
This does not mean you must make incremental updates. Updating most applications at once is still the best solution. Downloading two versions of React – even if one is lazily downloaded on demand – is still not ideal. For larger applications that are not actively maintained, this option makes sense to consider, and React 17 allows these applications to be left behind.
We have manufactured example warehouse showing how lazy to download an older version of React if necessary. This demo uses Create React, but it should be possible to follow a similar approach with any other tool. We welcome demos that use other tools as bet requests.
We are postponed other changes only after reaction 17. The goal of this publication is to enable incremental updates. If upgrading to React 17 were too difficult, it would lose its purpose.
To implement incremental updates, we need to make some changes to the React event system. React 17 is a major release because these changes can break. You can check us out version version FAQ learn more about our commitment to stability.
In React 17, React no longer attaches event handlers
document level under the hood. Instead, it attaches them to the root DOM, where the React tree is rendered:
const rootNode = document.getElementById('root'); ReactDOM.render(<App />, rootNode);
React in 16 and earlier React would do
document.addEventListener() for most events. React 17 calls
rootNode.addEventListener() instead under the Hood.
If you’re having trouble with this change, here is a common way to solve them.
React 17 RC blog post describes the remainder of the 17 disruptive changes in reaction.
We’ve only had to change less than 20 components out of 100,000+ in the Facebook product code to work with these changes We expect most applications to be able to upgrade to React 17 without too much hassle. Please tell us if you encounter problems.
React 17 supports new JSX variant. We have also supported its support for React 16.14.0, React 15.7.0 and 0.14.10. Note that it is completely optional and you do not need to use it. The classic JSX variant will continue to run and is not scheduled to stop supporting it.
React Native has a separate release schedule. We got support for React 17 in React Native 0.64. As always, you can follow React Native Community publishing discussions monitoring the problem.
To install React 17 at npm, run:
npm install firstname.lastname@example.org email@example.com
To install React 17 with Wire, run:
yarn add firstname.lastname@example.org email@example.com
We also offer React’s UMD structures via CDN:
<script crossorigin src="https://firstname.lastname@example.org/umd/react.production.min.js"></script> <script crossorigin src="https://email@example.com/umd/react-dom.production.min.js"></script>
See the documentation detailed installation instructions.
- Delegate events to roots and not
document. (@trueadm in # 18195 and other)
- Clean up all effects before performing the following effects. (@bvaughn in # 17947)
useEffectcleaning works asynchronously. (@bvaughn in # 17925)
- Use a browser
onBlur. (@trueadm in # 19186)
- Do everything
Captureevents use the browser capture phase. (@trueadm in # 19221)
- Do not mimic bubbling
onScrollevent. (@jaearon in # 19464)
- Throw if
undefined. (@jaearon in # 19550)
- Unlink events. (@trueadm in # 18969)
- Stop revealing internal parts that React Native Web does not need. (@necolas in # 18483)
- Connect all known event listeners when you’re just getting attached. (@jaearon in # 19659)
consoleDual mode dual rendering with a second render pass. (@Helsinki in # 18547)
- Cancel undocumented and misleading
ReactTestUtils.SimulateNativeAPI. (@jaearon in # 13407)
- Rename the private field names used in the internal parts. (@jaearon in # 18377)
- Do not call the User Timing API in development. (@jaearon in # 18417)
- Disable the console during repeated rendering in tight mode. (@Helsinki in # 18547)
- In tight mode, double render components even without hooks. (@ eps1lon in # 18430)
- Allow calling
ReactDOM.flushSyncduring life cycle methods (but beware). (@Helsinki in # 18759)
codefeature for keyboard event items. (@ bl00mber in # 18287)
videoelements. (@tombrowndev in # 18619)
inputelements. (@ eps1lon in # 18634)
- Warn when not
<Context.Provider>. (@ charlie1404 in # 19054)
- Warn when
undefined. (@bvaughn in # 19550)
- Fix the error message for invalid updates. (@JoviDeCroock in # 18316)
- Close forwardRef and memo on stack frames. (@Helsinki in # 18559)
- Improve the error message when switching between managed and unmanaged inputs. (@vakarl in # 17070)
onWheelpassive. (@jaearon in # 19654)
setStatehangs in development in a closed iframe. (@jaearon in # 19220)
- Fix lazy component rendering service
defaultProps. (@jddxf in # 18539)
- Correct the false positive warning when
undefined. (@ eps1lon in # 18676)
- Fix test utilities with atypical ones
requireimplementation. (@ just-Boris in # 18632)
onBeforeInputby reporting an incorrect
event.type. (@ eps1lon in # 19561)
event.relatedTargetindicated by name
undefinedIn Firefox. (@suomimeemit in # 19607)
- Fix an unspecified error in IE11. (@hemakshis in # 19664)
- Correct the rendering to a shadow root. (@ Jack-Works in # 15894)
movementX/Ypolyfill hijacking events. (@jaearon in # 19672)
- Use authorization
onResetProceedings. (@jaearon in # 19333)
- Improve memory usage. (@trueadm in # 18970)
useCallbackin accordance with the conduct
useMemofor server rendering. (@lexmckenley in # 18783)
- Correct the leaking condition when the action component throws. (@pmaccart in # 19212)