create react website in javascript

To create a React website using JavaScript, follow these steps:

  1. Install Node.js on your system.

  2. Create a new project directory and navigate to it in the terminal.

  3. Use the Node.js package manager (npm) to create a package.json file for your project:

index.tsx
npm init
9 chars
2 lines
  1. Install the necessary dependencies for your project (React, React-DOM, and Babel):
index.tsx
npm install react react-dom babel-cli babel-preset-react-app --save
68 chars
2 lines
  1. Create a new file in your project directory named index.js. This will be the entry point for your application.

  2. Add the following code to your index.js file to import React and ReactDOM, and render a basic React component to the DOM:

index.tsx
import React from 'react';
import ReactDOM from 'react-dom';

const App = () => {
  return (
    <div>
      <h1>Hello, World!</h1>
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));
211 chars
13 lines
  1. Create a new file in your project directory named .babelrc. This file will be used by Babel to transpile your code from JSX to regular JavaScript. Add the following code to your .babelrc file:
{
  "presets": ["react-app"]
}
31 chars
4 lines
  1. Create a new file in your project directory named index.html. This will be the HTML file that your React app will be rendered inside of.

  2. Add the following code to your index.html file to create a basic HTML structure, and link to your compiled JavaScript file:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>React App</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="dist/bundle.js"></script>
  </body>
</html>
196 chars
12 lines
  1. Configure Babel to transpile your JavaScript code by adding the following script to your package.json file:
{
  "scripts": {
    "build": "babel src/index.js -o dist/bundle.js"
  }
}
75 chars
6 lines
  1. Finally, run the following command in your terminal to start the Babel compiler and build your application:
index.tsx
npm run build
14 chars
2 lines

Your React website is now ready to be served! Open the index.html file in your browser to see your React app in action.

gistlibby LogSnag