Jak zbudować aplikację react?
- User
Jak zbudować aplikację react?
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Jak zbudować aplikację react?
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Poniżej znajdziesz szybki (ale konkretny) przepis na stworzenie i zbudowanie prostej aplikacji w React – od zera, aż po wersję produkcyjną.
Zainstaluj Node.js (w pakiecie jest też npm).
• Pobierz instalator z https://nodejs.org/
• Zweryfikuj instalację:
node -v # np. v18.x
npm -v # np. 9.x
(Opcjonalnie) Zainstaluj Yarn lub pnpm, jeśli wolisz inny menedżer paczek.
Masz dwa najpopularniejsze „startery”:
| Narzędzie | Zalety | Komenda startowa |
|---|---|---|
| Create React App (CRA) | proste, „jedno-kliknięcie”, dobrze znane | npx create-react-app my-app |
| Vite | szybszy dev-server 🔥, mniejszy bundle, banalny config | npm create vite@latest my-app -- --template react |
Załóżmy, że idziemy w CRA (ale Vite działa praktycznie identycznie).
npx create-react-app my-app
cd my-app
npm start # odpala lokalny serwer z hot-reloadem
Przeglądarka otworzy się na http://localhost:3000.
my-app/
├─ node_modules/ # zależności
├─ public/ # statyczne pliki (favicon, index.html)
├─ src/ # twój kod źródłowy
│ ├─ App.js
│ ├─ index.js # punkt wejścia
│ └─ ...
├─ package.json # skrypty, zależności
└─ README.md
Kluczowy plik startowy to src/index.js, gdzie React renderuje komponent App:
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import './index.css';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
Przykładowy, ultraprosty komponent:
// src/components/Counter.jsx
import { useState } from 'react';
export default function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(c => c + 1)}>
Kliknięto: {count} razy
</button>
);
}
A potem w App.js:
import Counter from './components/Counter';
function App() {
return (
<div className="App">
<h1>Moje pierwsze React-app</h1>
<Counter />
</div>
);
}
export default App;
Hot-reload sprawi, że zobaczysz efekty niemal natychmiast po zapisaniu pliku.
• Routing – react-router-dom
npm i react-router-dom
• Globalny stan – React Context, Redux Toolkit, Zustand…
• Stylowanie – CSS Modules, Styled-Components, Tailwind.
Na tym etapie wszystko zależy od potrzeb projektu.
Kiedy aplikacja działa lokalnie, czas na build:
npm run build
Powstanie folder build/ (CRA) lub dist/ (Vite) ze statycznymi plikami HTML/CSS/JS gotowymi do wrzucenia na serwer.
Kilka popularnych opcji (wrzucasz cały folder build/dist):
| Hosting | Komenda / sposób |
|---|---|
| Netlify | netlify deploy lub interfejs WWW (drag-and-drop) |
| Vercel | vercel (autokonfiguracja dla React) |
| GitHub Pages | npm i -D gh-pages i np. npm run deploy (przez gh-pages) |
| Dowolny VPS/S3 | wrzucasz statyczne pliki i serwujesz (Nginx, Apache, S3+CloudFront) |
package.json (CRA)"scripts": {
"start": "react-scripts start", # development
"build": "react-scripts build", # produkcja
"test": "react-scripts test", # Jest + React Testing Library
"eject": "react-scripts eject" # wyciąga config Webpack (raczej NIE rób)
}
npx create-react-app my-app --template typescript).npm run analyze (po source-map-explorer).npx create-react-app my-app → npm startsrc/, baw się stanem (useState, useEffect).npm run build → folder build/ na hosting.I to wszystko! Masz gotowy fundament pod rozwijanie własnej aplikacji w React. Powodzenia i udanego kodowania! 🚀