Site icon crypticknwoledge.com

React JS Creating First Project

Let’s create a project to print “Hello, world!” with React, you’ll need to create a new React project and write some JavaScript code to render the message to the page. Here’s how you can do that:

Open the “index.js” file and replace the existing code with the following:

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

ReactDOM.render(
  <h1>Hello, world!</h1>,
  document.getElementById('root')
);
npm start

That’s it! You’ve successfully printed “Hello, world!” with React. Now you can start building your React app by adding more components and functionality.

Here’s a more detailed explanation of the code you wrote:

import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
  <h1>Hello, world!</h1>,
  document.getElementById('root')
);
Exit mobile version