Reputation: 7712
Is there a way to know the runtime version of React in the browser?
Upvotes: 212
Views: 335694
Reputation: 61
console.log(React.version)
will print the version of the react running in your project.
Upvotes: -1
Reputation: 427
Use the command line commands for checking the version of the ReactJS. You can run the below command.
npm view react version
or
yarn view react version
Upvotes: 2
Reputation: 7887
React.version
is what you are looking for.
It is undocumented though (as far as I know) so it may not be a stable feature (i.e. though unlikely, it may disappear or change in future releases).
Example with React
imported as a script
const REACT_VERSION = React.version;
let root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<div>React version: {REACT_VERSION}</div>
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
<div id="root"></div>
Example with React
imported as a module
import { version } from 'react';
console.log(version);
Obviously, if you import React
as a module, it won't be in the global scope. The above code is intended to be bundled with the rest of your app, e.g. using webpack. It will virtually never work if used in a browser's console (it is using bare imports).
This second approach is the recommended one. Most websites will use it. create-react-app does this (it's using webpack behind the scene). In this case, React
is encapsulated and is generally not accessible at all outside the bundle (e.g. in a browser's console).
Upvotes: 196
Reputation: 1028
If you have the React DevTools extension enabled, you can execute this in the console:
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.renderers.get(1).version
Here's the output if I execute it on my website in production (nikolovlazar.com)
Upvotes: 19
Reputation: 1486
If you have already deployed your app which used webpack. You can use the below step to identify the "react" and "react-dom".
appName
.js file"webpack/sharing/consume/default/react/react?1aa9": () => (loadStrictVersionCheckFallback("default", "react", [,[1,17,0,0],[1,16,8,0],1],// ..SOMETHINNG
"webpack/sharing/consume/default/react-dom/react-dom?8d07": () => (loadStrictVersionCheckFallback("default", "react-dom", [,[1,17,0,0],[1,16,8,0],1], // ..SOMETHINNG
OR
register("react-dom", "17.0.2", () // ..SOMETHING
register("react", "17.0.2", ()// ..SOMETHINNG
Note: It only applicable for deployed app
Upvotes: 0
Reputation: 151
You can either run the following command(s) on your terminal, depending if you are using npm or yarn:
npm view react version
or
yarn view react version
Or You can also open your package.json file in your project under the "dependencies" check "react": after the semicolon will be the version of your react
Upvotes: 8
Reputation: 1396
This strategy should work all of the time: In the end React has to be included in a js file in the html through a script tag. So find that file and look for the React version.
Upvotes: 0
Reputation: 31
To know the react version, Open package.json file in root folder, search the keywork react. You will see like "react": "^16.4.0",
Upvotes: -2
Reputation: 494
First Install React dev tools if not installed and then use the run below code in the browser console :
__REACT_DEVTOOLS_GLOBAL_HOOK__.renderers.get(1).version
Upvotes: 16
Reputation: 1816
With the React Devtools installed you can run this from the browser console:
__REACT_DEVTOOLS_GLOBAL_HOOK__.renderers.forEach(r => console.log(`${r.rendererPackageName}: ${r.version}`))
Which outputs something like:
react-dom: 16.12.0
Upvotes: 68
Reputation: 2008
From the command line:
npm view react version
npm view react-native version
Upvotes: 162
Reputation: 1976
In an existing project a simple way to see the React version is to go to a render
method of any component and add:
<p>{React.version}</p>
This assumes you import React like this: import React from 'react'
Upvotes: 11
Reputation: 401
Open the console, then run window.React.version
.
This worked for me in Safari and Chrome while upgrading from 0.12.2 to 16.2.0.
Upvotes: 7
Reputation: 1217
In index.js file, simply replace App component with "React.version". E.g.
ReactDOM.render(React.version, document.getElementById('root'));
I have checked this with React v16.8.1
Upvotes: 4
Reputation: 101
For an app created with create-react-app I managed to see the version:
The app was deployed without source map.
Upvotes: 5
Reputation: 837
It is not certain that any global ECMAScript variables have been exported and html/css does not necessarily indicate React. So look in the .js.
Method 1: Look in ECMAScript:
The version number is exported by both modules react-dom and react but those names are often removed by bundling and the version hidden inside an execution context that cannot be accessed. A clever break point may reveal the value directly, or you can search the ECMAScript:
Method 2: Use a DOM breakpoint:
Inspect Element
Elements
paneBreak On… - subtree modifications
Sources
paneCall Stack
sub-panerender
entry, this is ReactDOM.render
render
, ie. the code that invokes renderreact-dom
module exports object
version: "15.6.2"
, ie. all values exported by react-dom
The version is also injected into React dev tools, but as far as I know not displayed anywhere.
Upvotes: 16
Reputation: 226
Open Chrome Dev Tools or equivalent and run require('React').version
in the console.
That works on websites like Facebook as well to find out what version they are using.
Upvotes: 16