Creating our first React component
The component is the essential part of React. With React you can build interactive and reusable components. In this recipe, you will create your first React component.
Getting ready
First, we need to create our React application using create-react-app. Once that is done, you can proceed to create your first React component.
Before you install create-react-app, remember that you need to download and install Node from www.nodejs.org. You can install it for Mac, Linux, and Windows.
Install create-react-app globally by typing this command in your Terminal:
npm install -g create-react-app
Or you can use a shortcut:
npm i -g create-react-appHow to do it...
Let's build our first React application by following these steps:
- Create our React application with the following command:
create-react-app my-first-react-app- Go to the new application with
cd my-first-react-appand start it withnpm start. - The application should now be running at
http://localhost:3000. - Create a new...