DEV Community

Mercy
Mercy

Posted on

Creating your first React App

Getting started with React can be an exciting journey, especially with the help of Create React App (CRA), a powerful tool that simplifies the setup process. This blog post will guide you through the steps to create your first React application using CRA.

What is Create React App?

Create React App is an officially supported way to create single-page applications using React. It sets up your development environment so you can use the latest JavaScript features, provides a nice developer experience, and optimizes your app for production without the need for complex configurations.

Prerequisites
Before you start, ensure you have the following installed on your machine:

  • Node.js: Version 14.0.0 or higher
  • npm: Version 5.6 or higher (comes bundled with Node.js) You can check if Node.js is installed by running this command in your terminal:

node -v

If it’s not installed, download it from the Node.js website.

Step-by-Step Guide to Create Your First React App
1. Install Create React App

Open your terminal and navigate to the directory where you want to create your new React application. Use the following command to create a new app named my-react-app:

npx create-react-app my-react-app

Using npx ensures that you're using the latest version of Create React App without needing to install it globally. If you had previously installed it globally, it's recommended to uninstall it first:

npm uninstall -g create-react-app

2. Navigate to Your Project Directory

Once the installation is complete, change into your project directory:

cd my-react-app

3. Start the Development Server
Now, you can start your React application by running:

npm start

This command will launch a new browser window displaying your new React app at http://localhost:3000. If it doesn't open automatically, you can manually enter that URL in your browser.

4. Explore Your Project Structure
Inside the my-react-app directory, you'll find several files and folders:

  • src/: This folder contains all your application code.
  • public/: Contains static files like index.html.
  • package.json: Lists dependencies and scripts for your project. The main file you'll interact with is src/App.js. Open this file in a text editor and modify it as follows:
function App() {
  return (
    <div className="App">
      <h1>Hello World!</h1>
    </div>
  );
}

export default App;
Enter fullscreen mode Exit fullscreen mode

5. Live Reloading

One of the great features of Create React App is live reloading. As soon as you save changes in App.js, you'll see them reflected in the browser without needing to refresh.

6. Building for Production
When you're ready to deploy your app, run:

npm run build

Conclusion

By so doing, You’ve just set up your first React application using Create React App. This tool not only streamlines the initial setup but also allows you to focus on building and learning React without getting bogged down by configuration details. Now that you're up and running, explore more about components, state management, and routing in React to enhance your application further.
By following these steps, you're well on your way to becoming proficient in building modern web applications with React!

Top comments (0)