03 Setup - biswajitsundara/react GitHub Wiki

Create a React App

The best way to create a react app is using the create-react-app command

  • Use the command npx create-react-app hello-world
  • npx is a package runner that gets downloaded along with npm.
  • If we want to create using npm then follow below two steps:
    • First install the create-react app globally npm install create-react-app -g
    • Second use the command create-react-app <project-name>

Simple Update

Go to App.js and edit the paragraph <p>Hello World</p>

Running the application

  • Use the command npm start
  • we will see the app http://localhost:3000/

Extensions

These are not specific to react and not mandatory however these VS code extensions will help

  • Prettier (Preferences -> Settings -> Default formatter -> Set Prettier)
  • Material Icon Theme

Install React developer tools browser extension - https://reactjs.org/link/react-devtools

React 18

  • Currently the react-app generates project in react-18 however the APIs are still pointing to 17 version
  • So make the below changes
  • Replace the react-dom import with import {createRoot} from 'react-dom/client'
  • Replace the ReactDOM.render with the below.
const container = document.getElementById('root');
const root = createRoot(container);
root.render(<App />);
⚠️ **GitHub.com Fallback** ⚠️