We don’t recommend depending on alphas in production code. If you’re currently using Hooks from an alpha build of React, note that this release does contain some small breaking changes to Hooks. As with all our minor releases, none of the changes break backwards compatibility. The above changelog contains all notable changes since our last stable release (16.7.0). Don’t consider throwing to be a rule violation.Fix reporting after encountering a loop.Add ReactTestRenderer.act() and ReactTestUtils.act() for batching updates so that tests more closely match real behavior.Fix wrong state in shouldComponentUpdate in the presence of getDerivedStateFromProps for Shallow Renderer.Support Hooks in the shallow renderer.
All other values, including null, are not allowed.
UNPKG REACTDOM CODE
We recommend to wrap any code rendering and triggering updates to your components into act() calls. It ensures that the behavior in your tests matches what happens in the browser more closely. We have added a new API called ReactTestUtils.act() in this release. We can’t wait to see what you’ll create next! Testing Hooks 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. If you want, you should be able to use Hooks in most of the new code you’re writing.Įven while Hooks were in alpha, the React community created many interesting examples and recipes using Hooks for animations, forms, subscriptions, integrating with other libraries, and so on. Currently, only getSnapshotBeforeUpdate() and componentDidCatch() methods don’t have equivalent Hooks APIs, and these lifecycles are relatively uncommon. Note that React Hooks don’t cover all use cases for classes yet but they’re very close. We described our plan for the next months in the recently published React Roadmap. It will soon be included into Create React App by default. We strongly recommend enabling a new lint rule called eslint-plugin-react-hooks to enforce best practices with Hooks. They are also supported in the latest Flow and TypeScript definitions for React. React Hooks are now supported by React DevTools. React Native will support Hooks in the 0.59 release. Hooks won’t work if you forget to update, for example, React DOM. Note that to enable Hooks, all React packages need to be 16.8.0 or higher. Yes! Starting with 16.8.0, React includes a stable implementation of React Hooks for: Code using Hooks will work side by side with existing code using classes. Instead, try using Hooks in some of the new components, and let us know what you think. We don’t recommend rewriting your existing applications to use Hooks overnight. The Hooks FAQ describes the gradual adoption strategy. Hooks have no breaking changes, and we have no plans to remove classes from React. showcases community-maintained Hooks recipes and demos.
Making Sense of React Hooks explores the new possibilities unlocked by Hooks.