Dark mode
สร้างโปรเจค React
วิธีสร้างโปรเจคด้วย Vite
bash
npm create vite@latest my-app -- --template react-ts
bash
pnpm create vite my-app --template react-ts
bash
yarn create vite my-app --template react-ts
bash
bun create vite my-app --template react-ts
หลังจากสร้างโปรเจค:
bash
cd my-app
npm install # หรือ pnpm install / yarn / bun install
npm run dev # หรือ pnpm dev / yarn dev / bun dev
สร้างโปรเจคด้วย Next.js
bash
npx create-next-app@latest
cd my-app
npm run dev
โครงสร้างโปรเจค
my-app/
├── node_modules/
├── public/
├── src/
│ ├── App.tsx
│ ├── main.tsx
│ └── ...
├── package.json
└── ...
ไฟล์ที่สำคัญ
src/main.tsx
: จุดเริ่มต้นของแอปsrc/App.tsx
: Component หลักsrc/index.css
: สไตล์หลัก
ตัวอย่างโค้ด
tsx
// src/App.tsx
function App() {
return (
<div className="App">
<h1>Hello React</h1>
</div>
);
}
export default App;