Skip to main content

User Experience (UX)

Migrating React from version 18 to 19

Reactv19

React 19 was released on 25 April 2024 and it is based out of React 18. This release introduces major improvements and removes some features to enhance developer experience and application performance. Migrating is a straightforward approach, but you need to watch for removed features. In this blog, I share my experience in migrating React to version 19.

Key Features added in React 19

  1. Optimized Concurrent Rendering:React introduced concurrent rendering in version 18. In React 19, they further improved it by scheduling algorithm dynamically to adapt user interactions.
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />, { adaptiveScheduling: true });
  1. New Hooks introduced
    • useActionState -> Update state based on the result of form submission.
    • useFormStatus -> Gives status information of the last form submission.
    • useOptimistic → Lets you  to optimistically update the UI.
  1. Actions API: React introduced Actions to handle mutations and state updates. It acts as an async function that gets called on form submission.

Deprecations & removals to consider

  • React removed String Refs. Use callback refs or createRef instead.
  • createFactory, render, element.ref and ReactDom.hydrate were removed.
  • React removed propTypes and defaultProps from package.

Step by step instructions for React 18 to 19 migration

Step1: Audit packages

Audit your package.json file and ensure it supports React 19. If not, upgrade the packages to the supported version.

Note: It is highly recommended to keep packages with the latest version.

Npm run audit

Step2: Update React version

npm install react@^19.0.0 react-dom@^19.0.0

Step3: Run Codemods

npx codemod@latest react/19/migration-recipe

Codemods will update the following

  • Replace ReactDOM.render with createRoot or hydrateRoot.
  • Convert String refs to callback refs or useRef.
  • Remove legacy Context APIs (contextTypes, getChildContext).

Step4: Address breaking issues

  • We used Material UI, where Grid2 was not supported. We switched from Grid2 to Grid.
  • React removed String Ref, so we replaced it with createRef.
  • We upgraded to the modern Context API like createContext and contextType.

Step5: Test and validate the application

Run the application and test the end-to-end flow. Look for performance, server-side rendering, lazy loading impacts as well.

Step6: Post migration cleans up

Update lint/eslint rules according to react 19.Remove unused imports and packages. Add dev notes for the breaking issues to faced/resolution took while migrating

Reference:

  1. React 19 Upgrade Guide – React
  2. Built-in React Hooks – React
  3. React 18 to 19 Migration – Codemod.com

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Vijayshri Govindarajan

Vijayshri Govindarajan is a senior technical consultant at Perficient with 7 years of experience in front-end development. She primarily works with JavaScript frameworks like React and Angular. She has deep expertise in user interaction-tracking technologies such as Content Square and Adobe Analytics. She is eager to explore and learn about new advancements happening around the industry.

More from this Author

Follow Us