React is a JavaScript library for building user interfaces.
29 Mar 2022 · Newest first
Last checked
Checking sources…
Showing 1 of 1 releases. Full release notes.
Signals highlight changes worth reviewing. They cannot determine whether your application is affected.
No suppression of console logs: When you use Strict Mode, React renders each component twice to help you find unexpected side effects. In React 17, we've suppressed console logs for one of the two renders to make the logs easier to read. In response to community feedback about this being confusing, we've removed the suppression. Instead, if you have React DevTools installed, the second log's renders will be displayed in grey, and there will be an option (off by default) to suppress them completely.
No warning about
setStateon unmounted components: Previously, React warned about memory leaks when you callsetStateon an unmounted component. This warning was added for subscriptions, but people primarily run into it in scenarios where setting state is fine, and workarounds make the code worse. We've removed this warning.
react-dom:ReactDOM.renderhas been deprecated. Using it will warn and run your app in React 17 mode.
react-dom:ReactDOM.hydratehas been deprecated. Using it will warn and run your app in React 17 mode.
react-dom:ReactDOM.unmountComponentAtNodehas been deprecated.
react-dom:ReactDOM.renderSubtreeIntoContainerhas been deprecated.
react-dom/server:ReactDOMServer.renderToNodeStreamhas been deprecated.
renderToString: Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest<Suspense>boundary and then retry rendering the same content on the client. It is still recommended that you switch to a streaming API likerenderToPipeableStreamorrenderToReadableStreaminstead.
Components can now render
undefined: React no longer throws if you returnundefinedfrom a component. This makes the allowed component return values consistent with values that are allowed in the middle of a component tree. We suggest to use a linter to prevent mistakes like forgetting areturnstatement before JSX.
renderToStaticMarkup: Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest<Suspense>boundary and retry rendering on the client.
Below is a list of all new features, APIs, deprecations, and breaking changes. Read React 18 release post and React 18 upgrade guide for more information.
useId is a new hook for generating unique IDs on both the client and server, while avoiding hydration mismatches. It is primarily useful for component libraries integrating with accessibility APIs that require unique IDs. This solves an issue that already exists in React 17 and below, but it’s even more important in React 18 because of how the new streaming server renderer delivers HTML out-of-order.startTransition and useTransition let you mark some state updates as not urgent. Other state updates are considered urgent by default. React will allow urgent state updates (for example, updating a text input) to interrupt non-urgent state updates (for example, rendering a list of search results).useDeferredValue lets you defer re-rendering a non-urgent part of the tree. It is similar to debouncing, but has a few advantages compared to it. There is no fixed time delay, so React will attempt the deferred render right after the first render is reflected on the screen. The deferred render is interruptible and doesn't block user input.useSyncExternalStore is a new hook that allows external stores to support concurrent reads by forcing updates to the store to be synchronous. It removes the need for useEffect when implementing subscriptions to external data sources, and is recommended for any library that integrates with state external to React.useInsertionEffect is a new hook that allows CSS-in-JS libraries to address performance issues of injecting styles in render. Unless you’ve already built a CSS-in-JS library we don’t expect you to ever use this. This hook will run after the DOM is mutated, but before layout effects read the new layout. This solves an issue that already exists in React 17 and below, but is even more important in React 18 because React yields to the browser during concurrent rendering, giving it a chance to recalculate layout.These new APIs are now exported from react-dom/client:
createRoot: New method to create a root to render or unmount. Use it instead of ReactDOM.render. New features in React 18 don't work without it.hydrateRoot: New method to hydrate a server rendered application. Use it instead of ReactDOM.hydrate in conjunction with the new React DOM Server APIs. New features in React 18 don't work without it.Both createRoot and hydrateRoot accept a new option called onRecoverableError in case you want to be notified when React recovers from errors during rendering or hydration for logging. By default, React will use reportError, or console.error in the older browsers.
These new APIs are now exported from react-dom/server and have full support for streaming Suspense on the server:
renderToPipeableStream: for streaming in Node environments.renderToReadableStream: for modern edge runtime environments, such as Deno and Cloudflare workers.The existing renderToString method keeps working but is discouraged.
react-dom: ReactDOM.render has been deprecated. Using it will warn and run your app in React 17 mode.react-dom: ReactDOM.hydrate has been deprecated. Using it will warn and run your app in React 17 mode.react-dom: ReactDOM.unmountComponentAtNode has been deprecated.react-dom: ReactDOM.renderSubtreeIntoContainer has been deprecated.react-dom/server: ReactDOMServer.renderToNodeStream has been deprecated.flushSync.<Suspense> boundary in the tree. This ensures the hydrated tree is consistent and avoids potential privacy and security holes that can be caused by hydration mismatches.Promise, Symbol, and Object.assign. If you support older browsers and devices such as Internet Explorer which do not provide modern browser features natively or have non-compliant implementations, consider including a global polyfill in your bundled application.undefined: React no longer throws if you return undefined from a component. This makes the allowed component return values consistent with values that are allowed in the middle of a component tree. We suggest to use a linter to prevent mistakes like forgetting a return statement before JSX.act warnings are now opt-in: If you're running end-to-end tests, the act warnings are unnecessary. We've introduced an opt-in mechanism so you can enable them only for unit tests where they are useful and beneficial.setState on unmounted components: Previously, React warned about memory leaks when you call setState on an unmounted component. This warning was added for subscriptions, but people primarily run into it in scenarios where setting state is fine, and workarounds make the code worse. We've removed this warning.renderToString: Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest <Suspense> boundary and then retry rendering the same content on the client. It is still recommended that you switch to a streaming API like renderToPipeableStream or renderToReadableStream instead.renderToStaticMarkup: Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest <Suspense> boundary and retry rendering on the client.useTransition and useDeferredValue to separate urgent updates from transitions. (#10426, #10715, #15593, #15272, #15578, #15769, #17058, #18796, #19121, #19703, #19719, #19724, #20672, #20976 by @acdlite, @lunaruan, @rickhanlonii, and @sebmarkbage)useId for generating unique IDs. (#17322, #18576, #22644, #22672, #21260 by @acdlite, @lunaruan, and @sebmarkbage)useSyncExternalStore to help external store libraries integrate with React. (#15022, , , , , , , by , , and )createRoot and hydrateRoot. (#10239, #11225, #12117, #13732, #15502, #15532, #17035, #17165, #20669, #20748, #20888, #21072, #21417, #21652, #21687, #23207, #23385 by @acdlite, @bvaughn, @gaearon, @lunaruan, @rickhanlonii, @trueadm, and @sebmarkbage)renderToNodeStream. (#23359 by @sebmarkbage)act is used in production. (#21686 by @acdlite)global.IS_REACT_ACT_ENVIRONMENT. (#22561 by @acdlite)act batch updates. (#21797 by @acdlite)exports field to package.json. (#23087 by @otakustay)lazy support. (#24068 by @gnoff)globalThis instead of window for edge environments. (#22777 by @huozhi)scheduler/tracing APIstartTransition as a version of useTransition without pending feedback. (#19696 by @rickhanlonii)useInsertionEffect for CSS-in-JS libraries. (#21913 by @rickhanlonii)<StrictMode> re-run effects to check for restorable state. (#19523 , #21418 by @bvaughn and @lunaruan)object-assign polyfill. (#23351 by @sebmarkbage)fallback={undefined} now behaves the same as null and isn't ignored. (#21854 by @rickhanlonii)lazy() resolving to the same component equivalent. (#20357 by @sebmarkbage)useReducer observing incorrect props by removing the eager bailout mechanism. (#22445 by @josephsavona)NaN. (#23333 by @hachibeeDI)onResize event to video elements. (#21973 by @rileyjshaw)<option> children if value is provided. (#21431 by @sebmarkbage)