ssd-react-component
Installation
SKILL.md
SSD React Component — มาตรฐานการเขียน React Component
บริบท
การเขียน React component ของ SSD ต้องใช้รูปแบบ functional component ด้วย TypeScript (TSX) และต้องปฏิบัติตาม naming convention ที่กำหนด เพื่อให้โค้ดอ่านง่าย บำรุงรักษาง่าย และสามารถทำ automation test ได้
กฎหลัก
- ต้องสร้าง 1 component ต่อ 1 ไฟล์ (ยกเว้น Stateless/Pure components)
- ต้องใช้ TSX ร่วมกับ React เสมอ ห้ามใช้
React.createElement - ต้อง declare Props type และ export ออกมาทุกครั้งที่มี Props
- ชื่อ Props type ต้องตั้งตามรูปแบบ
[ComponentName]Props - ต้องใช้ arrow function สำหรับ event handler
- ต้องใช้ shorthand fragment
<>...</>แทน<React.Fragment> - ต้องใช้
ref callbackไม่ใช้ string ref