9951 explained code solutions for 126 technologies


reactjsHow do I create an app using ReactJS?


  1. To create an app using ReactJS, you need to install the React and ReactDOM libraries. You can do this with npm by running npm install react react-dom.

  2. Then, create a new file called index.js and add the following code:

import React from 'react';
import ReactDOM from 'react-dom';

ReactDOM.render(
  <h1>Hello, world!</h1>,
  document.getElementById('root')
);
  1. This code will render the text "Hello, world!" in an element with the ID of root (which you'll need to add to your HTML file).

  2. Next, create an HTML file called index.html and add the following code:

<html>
  <head>
    <title>My React App</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="index.js"></script>
  </body>
</html>
  1. Now, open index.html in your browser and you should see the text "Hello, world!"

  2. To build a more complex app, you can create components and render them in the index.js file. You can also use libraries like React Router to handle routing.

  3. For more information, check out the React documentation.

Edit this code on GitHub