React - Basics Tutorial

ReactJS Installation

To install React, you can follow these steps:

  1. Make sure you have Node.js installed on your computer. You can download it from the official Node.js website and follow the installation instructions for your operating system.
  2. Once Node.js is installed, you can open a command prompt or terminal window.
  3. Create a new directory for your React project. You can do this by running the following command:

    mkdir my-react-app
  4. Change into the new directory:

    cd my-react-app
  5. Initialize a new Node.js project by running the following command:

    npm init -y
  6. Now, you can install React and its dependencies. Run the following command:

    npm install react react-dom
  7. Once the installation is complete, you can start writing React code in your project. You can create a new JavaScript file, such as index.js, and import React as necessary.

    Here’s a simple example to get you started:

    import React from 'react';
    import ReactDOM from 'react-dom';
    const App = () => {
      return <h1>Hello, React!</h1>;
    ReactDOM.render(<App />, document.getElementById('root'));
  8. To see your React app in action, you need to create an HTML file, such as index.html. Add a div element with an id of “root” where your React app will be rendered.

    <!DOCTYPE html>
    <html lang="en">
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>My React App</title>
      <div id="root"></div>
      <script src="index.js"></script>
  9. Finally, open index.html in a web browser, and you should see “Hello, React!” displayed on the page.

That’s it! You have successfully installed React and set up a basic React project. Happy coding!

Leave a Reply