How to create a simple React App
Prerequisites
- Node.js installed
- A code editor (e.g. Visual Studio Code)
Creating a new React App
npx create-react-app my-app
Structure of a React App
The following files and directories are created:
- node_modules/: Contains the dependencies installed by npm.
- public/: Contains the static files (e.g. HTML, CSS, images).
- package.json: Contains the project’s metadata and dependencies.
- .gitignore: Contains the files that should be ignored by Git.
- src/: Contains the React components and code.
Starting the app
npm start
This will start a development server at http://localhost:3000
.
Modifying the app
Open the src/App.js
file and modify the following line:
returnHello, world!
;
to:
returnHello, {name}!
;
where {name}
is a prop that you can pass to the App
component.
Save the changes and the browser will automatically reload.
Conclusion
This was a quick introduction to creating a simple React app. For more information, please refer to the official React documentation.
Kind regards B. Guzman.