Prompt templates, kesilapan biasa, dan checklist deployment untuk React + Vibe Coding.
Gunakan template-template ini untuk berkomunikasi dengan AI. Isi tempat kosong [dalam kurungan] dengan maklumat spesifik projek anda.
Struktur Prompt yang Berkesan: (1) Beri konteks — apa stack/app anda, (2) Nyatakan APA nak dibina, (3) Spesifik tentang feature/detail, (4) Nyatakan format output yang diingini.
Pelajar selalu buat kesilapan yang sama. Kenali dan elakkan mereka:
"Bina component" — terlalu vague. AI tak tahu apa yang anda nak. Hasilnya component yang generic dan tak guna.
✅ Jadi spesifik: "Bina product card component dengan image, title, price, rating stars, dan add-to-cart button. Guna Tailwind CSS."
AI tak tahu apa stack, framework, atau setup anda. Ia mungkin suggest cara yang tak compatible dengan projek anda.
✅ Mulakan prompt dengan konteks: "Saya guna React + Vite + Tailwind CSS. Saya nak..."
Minta AI hasilkan entire app dalam satu prompt. Hasilnya terlalu generic dan susah nak debug.
✅ Pecah kepada langkah kecil: (1) Setup projek, (2) Bina component A, (3) Bina component B, (4) Sambungkan. Test setiap langkah sebelum proceed.
React JSX syntax hanya berfungsi dalam fail dengan extension .jsx (atau .tsx untuk TypeScript). Kalau guna .js, React akan confused.
✅ Sentiasa guna extension .jsx untuk fail React component. Contoh: Card.jsx, Button.jsx, bukan Card.js.
Pasang dependency baru (react-router-dom, supabase-js) tapi lupa restart npm run dev. App buat tak tahu dependency baru.
✅ Lepas install dependency baru, STOP server (Ctrl+C) dan start semula (npm run dev). Jangan refresh browser je — kena restart server.
Bila component tak muncul, pelajar terus panik dan minta AI tulis semula kod. Sebenarnya error dah tertera di browser console (F12).
✅ Buka browser console (F12 > Console). Baca error. Copy error ke AI dengan prompt template #8. Jangan teka-teka apa masalah.
Tulis component cantik-cantik tapi lupa tambah export default. Bila import dalam App.jsx, dapat error "Module not found" atau component undefined.
✅ Pastikan setiap component fail ada export default NamaComponent; di baris terakhir. Check AI-generated code untuk line ni.
Hardcode Supabase URL dan anon key terus dalam kod. Bila push ke GitHub, keys terbocor. Bila deploy, keys tak sama dengan production.
✅ Guna .env file dengan prefix VITE_. Contoh: VITE_SUPABASE_URL=.... Jangan commit .env ke Git. Set environment variables di platform deployment.
Deploy React app dengan React Router. Semua jalan di localhost. Tapi bila deploy, refresh page terus 404. Sebab server cuba cari file /about secara fizikal.
✅ Buat fail public/_redirects dengan content: /* /index.html 200. AI boleh tolong buatkan fail ni. Jangan lupa commit sebelum deploy!
AI kadang-kadang generate code yang guna syntax lama (React class components) atau pattern yang deprecated. Atau guna library yang tak compatible.
✅ Minta AI guna React Hooks (functional components) dan Tailwind CSS. Kalau nampak class MyComponent extends React.Component, minta AI tulis semula guna functional component dengan hooks.
Gunakan checklist ini setiap kali anda deploy React app ke production. Tick setiap item sebelum deploy.
Pro Tip: Simpan checklist ni sebagai DEPLOY_CHECKLIST.md dalam root projek React anda. Setiap kali nak deploy, buka dan tick satu persatu. Amalan ini akan elakkan 90% masalah deployment!.
| Tujuan | Command / Prompt |
|---|---|
| Setup React + Vite | npm create vite@latest . -- --template react |
| Install Tailwind (Vite) | npm install -D tailwindcss @tailwindcss/vite |
| Install React Router | npm install react-router-dom |
| Install Supabase | npm install @supabase/supabase-js |
| Run dev server | npm run dev |
| Build for production | npm run build |
| SPA redirect file | Content public/_redirects: /* /index.html 200 |
| Vite env prefix | VITE_NAMA_VARIABLE (wajib VITE_ prefix) |
Ingat: Tak perlu hafal command-command ni. Cuma perlu tahu command apa yang wujud. Bila perlu, minta AI ingatkan. Tapi having this reference sheet helps speed things up!