π Your First React App
Now that youβve set up React, letβs build your very first app β a simple "Hello, React!" component.
π Project Structure
If you used Create React App or Vite, youβll see a structure like this:
my-app/ βββ public/ βββ src/ β βββ App.jsx β βββ main.jsx β βββ index.css βββ package.json
π§± Creating a Component
Open App.jsx and replace the content with a simple React component:
import React from 'react';
function App() {
return (
<div>
<h1>Hello, React!</h1>
</div>
);
}
export default App;
In main.jsx (or index.js), React renders the App:
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
π» Run the App
In your terminal, start the development server:
npm run dev
Visit http://localhost:5173 (Vite) or http://localhost:3000 (CRA) to see your app running!
β Recap
- You created a React component
- You rendered it to the DOM
- You started the app using a dev server