score:171
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;
ReactDOM.render(
<div>React version: {REACT_VERSION}</div>,
document.getElementById('root')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="root"></div>
Example with React
imported as a module
import React from 'react';
console.log(React.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).
score:-3
To know the react version, Open package.json file in root folder, search the keywork react. You will see like "react": "^16.4.0",
score:0
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.
- Look through all the scripts included in the HTML (view source)
- One of the links include the script to React. WebPack lumps the libraries together under a common-xxxx.js file
- Open that script file and ctrl + f search for React
- Presto, version number there
score:0
If you have already deployed your app which used webpack. You can use the below step to identify the "react" and "react-dom".
- Open DeveloperTool in your browser
- Go to Source Tab
- Check your
appName
.js file - Search for "react" or "react-dom" You will find something like below. That will be the version your react-app is using.
"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
score:3
For an app created with create-react-app I managed to see the version:
- Open Chrome Dev Tools / Firefox Dev Tools,
- Search and open main.XXXXXXXX.js file where XXXXXXXX is a builds hash /could be different,
- Optional: format source by clicking on the {} to show the formatted source,
- Search as text inside the source for react-dom,
- in Chrome was found: "react-dom": "^16.4.0",
- in Firefox was found: 'react-dom': '^16.4.0'
The app was deployed without source map.
score:3
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
score:4
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
score:5
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'
score:5
score:7
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.
score:10
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
score:13
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:
- Load the Web page (you can try https://www.instagram.com they’re total Coolaiders)
- Open Chrome Developer Tools on Sources tab (control+shift+i or command+shift+i)
- Dev tools open on the Sources tab
- In the very right of the top menu bar, click the vertical ellipsis and select search all files
- In he search box down on left type FIRED in capital letters, clear the checkbox Ignore case, type Enter
- One or more matches appear below. The version is an export very close to the search string looking like version: "16.0.0"
- If the version number is not immediately visible: double click a line that begins with a line number
- ECMAScript appears in the middle pane
- If the version number is not immediately visible: click the two braces at bottom left of the ECMAScript pane {}
- ECMAScript is reformatted and easier to read
- If the version number is not immediately visible: scroll up and down a few lines to find it or try another search key
- If the code is not minified, search for ReactVersion There should be 2 hits with the same value
- If the code is minified, search for either SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED or react-dom
- Or search for the likely version string itself: "15. or "16. or even "0.15
Method 2: Use a DOM breakpoint:
- Load the page rendered by React
- Right click a React element (anything, like an input field or a box) and select
Inspect Element
- Chrome Developer Tools displays the
Elements
pane
- Chrome Developer Tools displays the
- As high up in the tree as possible from the selected element, but no higher than the React root element (often a div directly inside body with id root: <div id="root">), right click an element and select
Break On… - subtree modifications
- Note: It is possible to compare contents of the Elements tab (DOM current state) with the response for the same resouce on the Networks tab. This may reveal React’s root element
- Reload the page by clicking Reload left of the address bar
- Chrome Developer Tools stops at the breakpoint and displays the
Sources
pane
- Chrome Developer Tools stops at the breakpoint and displays the
- In the rightmost pane, examine the
Call Stack
sub-pane - As far down the call stack as possible, there should be a
render
entry, this isReactDOM.render
- Click the line below
render
, ie. the code that invokes render - The middle pane now displays ECMAScript with an expression containing .render highlighted
- Hover the mouse cursor over the object used to invoke render, is. the
react-dom
module exports object- if the code line goes: Object(u.render)(…, hover over the u
- A tooltip window is displayed containing
version: "15.6.2"
, ie. all values exported byreact-dom
The version is also injected into React dev tools, but as far as I know not displayed anywhere.
score:16
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.
score:38
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
score:127
From the command line:
npm view react version
npm view react-native version
Source: stackoverflow.com
Related Query
- How can one tell the version of React running at runtime in the browser?
- How can you access the constant variables of one Component in another Component - React
- How can I create a counter as components to use multiple times and create one button to reset all the counter in React JS?
- How i can apply a background image to the body of only ONE Component React
- How can I access the browser API in a React firefox extension sidebar?
- Im using React Router and I want one of my route links with path="/" to be the home page on reload.. How can you do that?
- How can I stop the Select component from closing when I clicked one of its item(Input element) - react antd
- How can I tell react router v4 where to load the component?
- How can I apply classNames in react to change the background color of one of the child div in React
- How can I convert the this cascading dropdown class component to functional one using React Hooks?
- How can i make required to click one of the toggle buttons in react form?
- How can I change the state of one React component based on the value of its sibling?
- How can i make mandatory to click one of the toggle buttons in react form?
- React: How much can I manipulate the DOM React has rendered?
- How can one extend React types to support html attributes as props?
- How can I write an else if structure using React (JSX) - the ternary is not expressive enough
- How can I remove unused imports/declarations from the entire project of React Typescript?
- How can remove console.log in the production build of a React application created using create-react-app?
- React hook form: How to can I use onChange on React Hook Form Version 7.0
- How can I call methods on Reactjs components in the browser console or from an outside script?
- How can I get the device's ip on React Native?
- Suddenly React cannot execute the 'create-react-app' command. Why is this happening and how can I solve it?
- How can I get the URL address from the browser in ReactJS (servers URL)
- How can I get a variable from the path in react router?
- How can I prevent the unmount in React Components?
- How can I change the color of a Link in React with Material-UI?
- How can i load a JSON configuration in runtime in a React app?
- How can I change the format for react datepicker days of the week?
- How can I clear the localstorage when user close react application window?
- How to make the entries in one column clickable in React Table?
More Query from same tag
- Are callbacks that are passed into other functional components updated on refresh?
- How to remove unchecked items from cart state in React
- updating object props with given users id context api react
- file input ref triggering file-picker twice
- API Fetch update only one data
- material-ui form label positions
- Argument of type 'HTMLCanvasElement | null' is not assignable to parameter of type
- How to access promise when using await
- Why is WebView in react native not opening?
- ReactJS: How can I create multi-level array using Map
- Problem with react useState falling behind one step
- React-Redux Store is not properly changed by reducer
- make follow and unfollow button in react(changing button)
- NextJS how to fetch data after click event?
- Pass id as props in react-router-dom
- Create React App Excluding mapbox-gl explicitly from transpilation
- How to dynamically display moment date in React
- React: onClick handler is getting called on every render?
- Better way to use useState hook for setting the boolean state in React
- Unexpected token p in JSON at position 0 in fetch
- How to convert all values to lower case to sort them
- Next.js Vanilla JS script won't run on deployment
- Material UI Autocomplete show suggestions in table format with header attached to it
- How do I call e.target.value only once?
- Get the selected seats to Parent in Reactjs
- How to import mulitple variables or list from another component in React JS?
- Bootstrap in React -- can't resolve jQuery Module?
- Image with public URL from GCS won't display immediately after state update but works after refreshing the page
- Variable set by setState not visible in keyboard handler event
- Access items in multideimension array