Skip to content
Tutorials Center
My learning

Topics

React Reference ยท Top-Level React APIs

React.version

Reference for React.version and ReactDOM.version: the string that tells you which React build is loaded, how to parse it and when to use it.

version is a plain string exported by the react package. It holds the semantic version of the React build that is actually loaded, for example "19.3.1". react-dom exports its own version with the same format.

Most apps never need it: you pin versions in package.json. It is useful for diagnostics (an error report, a debug panel) and for libraries that must behave differently on different major versions.

JSX
import { version } from 'react';
import { version as domVersion } from 'react-dom';

console.log(version, domVersion);

Try it

Reading the version
Branching on the major version

Syntax

JSX
import { version } from 'react';
import * as ReactDOM from 'react-dom';

const reactVersion = version;
const domVersion = ReactDOM.version;
Export Type Description
React.version string Version of the loaded react package.
ReactDOM.version string Version of the loaded react-dom package.

It is a constant, not a function. Pre-release builds carry a suffix such as 19.0.0-rc.1 or a canary hash, so parse defensively.

Usage notes

  • Compare the major number rather than the whole string. Number(version.split('.')[0]) is stable; string comparison of "19.10.0" and "19.9.0" is not.
  • react and react-dom must have the same version. A mismatch causes confusing runtime errors, and comparing the two strings is a cheap sanity check in a debug page.
  • The value describes the code that is loaded, which can differ from package.json when a bundler deduplicates packages or a CDN import map pins another build.
  • Feature detection is almost always better than version checks. Test typeof use === 'function' rather than "version at least 19" when you can.
  • Do not send the version to analytics on every render. Read it once at module level.
  • Server and client bundles can differ. During hydration problems, log both versions.