After running npx create-react-app my-app, the generated project will have the following structure:
my-app/
│── node_modules/
│── public/
│── src/
│── .gitignore
│── package.json
│── README.md
node_modules/ Foldernpm install.public/ Folderindex.html file.public/ are:
index.html: The main HTML file where the React app is injected.favicon.ico: The site’s favicon (icon in the browser tab).manifest.json: Metadata for Progressive Web Apps (PWA).📌 Example: index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>React App</title>
</head>
<body>
<div id="root"></div> <!-- React app gets injected here -->
</body>
</html>
src/ Folder (Main Codebase)This is where the React components, styles, and logic are written. The key files include:
index.jsApp.js) into the root div in index.html.📌 Example: index.js
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
ReactDOM.render(<App />, document.getElementById("root"));
App.js📌 Example: App.js
import React from "react";
function App() {
return (
<div>
<h1>Welcome to My React App</h1>
</div>
);
}
export default App;
App.cssApp.js component.components/ Folder (Best Practice)components/ folder inside src/ for reusable UI components.📌 Example: src/components/Header.js
import React from "react";
function Header() {
return <h2>This is the Header Component</h2>;
}
export default Header;
📌 Now import it inside App.js:
import Header from "./components/Header";
function App() {
return (
<div>
<Header />
<h1>Welcome to My React App</h1>
</div>
);
}
.gitignore Filenode_modules/
.env
build/
package.json File📌 Example snippet from package.json:
{
"name": "my-app",
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"scripts": {
"start": "react-scripts start"
}
}
To keep the project clean and maintainable, follow these best practices:
✅ Create a components/ folder to store reusable components.
✅ Use a pages/ folder if the app has multiple pages (e.g., Home, About, Contact).
✅ Keep assets (images, fonts, etc.) inside src/assets/ for better organization.
✅ Use separate CSS files for styling each component.
src/ folder contains the main application logic with components and styles.