How to check the version of ReactJS ?
React is a Javascript front-end library that is used to build single-page applications (SPA). Knowing the version can help you understand the available features, check for updates, and ensure compatibility with other dependencies. In this article, we will explore different methods to check the version of ReactJS.
To check the version of React we can use these 3 approaches:
Table of Content
- Using package.json file
- Using the command line
- Using the version property of default import from React
Approach 1: Using the package.json file
The package.json contains metadata about our project. It is created by default when we create our React project. We can create a react app using the command mentioned below.
npx create-react-app name_of_the_app
The package.json file contains a lot of information in the name/value pairs in JSON format. We can easily check our React version under the list of dependencies as shown in the image given below.
Approach 2: Using the command line
We can easily check the React version by using the command mentioned below on our command line.
npm view react version
The output demonstrating the use of the above command on the command line is mentioned below.
Approach 3: Using the version property of default import from React
The default import from React library is an object that has a version property on it. We can use this property inside our JSX elements in our desired manner.
Syntax:
import React from 'react';
let a = React.version
To follow along with the article create a react project using the command that was discussed above in the article.
Example: This example demonstrates the use of the version property on React object.
Javascript
// Filename - App.js import React from "react" ; const App = () => { return ( <h1> We are currently using react version{ " " } {React.version} </h1> ); }; export default App; |
Step to run the application: Use the following command on the command line to start the application.
npm start
Output: Open the browser and go to http://localhost:3000, you will see the following output.
Contact Us