leojh leojh - 6 months ago 84
React JSX Question

How can one tell the version of React running at runtime in the browser?

Is there a way to know the runtime version of React in the browser?

Answer Source

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).

const REACT_VERSION = React.version;

ReactDOM.render(
  <div>React version: {REACT_VERSION}</div>,
  document.getElementById('content')
);
<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="content"></div>

If you import react as a module, React won't be in the global scope (that is the point of modules). You need to import it first (that you are using commonJS or ES modules). For example, if you are using commonJS you should write:

const React = require('react');

console.log(React.version);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download