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

前端 未结 12 1725
抹茶落季
抹茶落季 2020-12-12 23:07

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

相关标签:
12条回答
  • 2020-12-12 23:46

    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
    
    0 讨论(0)
  • 2020-12-12 23:47

    To know the react version, Open package.json file in root folder, search the keywork react. You will see like "react": "^16.4.0",

    0 讨论(0)
  • 2020-12-12 23:49

    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

    0 讨论(0)
  • 2020-12-12 23:49

    From command line to view react version, npm view react version

    0 讨论(0)
  • 2020-12-12 23:53

    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.

    0 讨论(0)
  • 2020-12-12 23:54

    For an app created with create-react-app I managed to see the version:

    1. Open Chrome Dev Tools / Firefox Dev Tools,
    2. Search and open main.XXXXXXXX.js file where XXXXXXXX is a builds hash /could be different,
    3. Optional: format source by clicking on the {} to show the formatted source,
    4. Search as text inside the source for react-dom,
    5. in Chrome was found: "react-dom": "^16.4.0",
    6. in Firefox was found: 'react-dom': '^16.4.0'

    The app was deployed without source map.

    0 讨论(0)
提交回复
热议问题