Usually you know what version of React your app is using by opening the package.json, or poking around in node_modules/react/index.js. But perhaps there are many packaging abstractions in between your command line and the server. Especially if you have a continous integration server that builds your static assets and if that CI uses caching. It might get scary.

If you really want to print out what version of React is rendering your app here's one way to do that:


import React from 'react'

class Introspection extends React.Component {
  render() {
    return <div>
      Currently using React {React.version}
    </div>
  }
}

Suppose that you want this display to depend on the app being in dev or prod mode:


import React from 'react'

class Introspection extends React.Component {
  render() {
    return <div>
      {
        process.env.NODE_ENV === 'development' ?
        <p>Currently using React {React.version}</p> : null
      }
    </div>
  }
}

Note that there's no need to import process.

See this CodeSandbox snippet for a live example.

Comments

Anonymous

thanks!

Your email will never ever be published.

Previous:
Whatsdeployed facelift January 5, 2018 Python, Web development, Mozilla, Docker
Next:
Understanding Redis hash-max-ziplist-entries January 8, 2018 Python, Redis
Related by category:
Switching from Next.js to Vite + wouter July 28, 2023 JavaScript, React
How to SSG a Vite SPA April 26, 2025 JavaScript, React
An ideal pattern to combine React Router with TanStack Query November 18, 2024 JavaScript, React
swr compared to @tanstack/react-query August 30, 2024 JavaScript
Related by keyword:
More productive than Lisp? Really??! March 10, 2011 Python
Ugly one-liner to debug an object in Zope March 31, 2005 Zope