When you create a React app using tools like Vite or Create React App (CRA), a default folder structure is generated for you. Understanding this structure helps you keep your project clean, scalable, and easy to maintain.
The two most important files in the src folder are index.js and App.js. Together they form the entry point of your React application.
? Entry Point = Where your React app starts running
index.js connects React to the HTML file (usually public/index.html).App.js is the main/root component that returns the UI (JSX).App.js into a special HTML element with id root.A typical React project (Vite/CRA) looks something like this:
// Typical React project structure
my-react-app/
│
├── node_modules/ → Installed dependencies
├── public/ → Static assets (favicon, index.html)
├── src/ → Source code of your React app
│ ├── App.js → Main component of the app
│ ├── App.css → Styling for App component
│ ├── index.js → Entry point that renders the app
│ ├── components/ → Folder for reusable UI components
│ └── assets/ → Images, icons, or other resources
│
├── package.json → App configuration and dependencies
├── vite.config.js → (For Vite) Build configuration
└── README.md → Project documentation
Most of your day-to-day React work happens inside the src folder, especially in index.js and App.js.
The index.js file is the starting point of every React application. It connects the React code with the HTML file’s root div and tells React where to render your UI.
// index.js - React app entry file
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
ReactDOM.createRoot(...) creates a React “root” connected to the HTML element with id root.<App /> is your main component, which contains the rest of the UI.<React.StrictMode> helps catch potential problems during development.App.js appears inside the browser window.App.js is the root component of your application. It defines what content or components should be displayed on the page.
// App.js - main UI component
function App() {
return (
<div>
<h1>Welcome to My React App!</h1>
<p>This content is rendered through App.js</p>
</div>
);
}
export default App;
This file is imported into index.js, making it the central piece of your React UI. Any other components you create (like Header, Footer, etc.) are usually used inside App.js.
index.js is responsible for rendering the app into the browser.App.js defines the structure and layout of the UI.App.js automatically update the webpage through React’s Virtual DOM.In simple terms: index.js loads App.js → App.js returns JSX → React renders it into HTML inside the root div.
public/index.html (which contains a <div id="root">).index.js finds that root element and creates a React root.index.js tells React to render the <App /> component into that root.App.js returns JSX (your UI), which React converts into real DOM elements on the page.index.js clean — it should only handle rendering, not complex logic.components folder.export default (or named exports) for easy imports.pages/, hooks/, and context/ to keep things organized.index.js and App.js in the src directory.App.js to display your name and your favorite quote.components/ and create a file Header.js with a heading component.
// Header.js - simple reusable header
function Header() {
return (
<header>
<h2>My First React Header</h2>
<p>Organized inside the components folder</p>
</header>
);
}
export default Header;
Now import and display the Header component inside App.js:
// App.js - using the Header component
import Header from './components/Header';
function App() {
return (
<div>
<Header />
<p>This content is rendered through App.js</p>
</div>
);
}
export default App;