ประเภท | Best Practice | คำอธิบาย | ตัวอย่าง |
---|---|---|---|
Component Names | ใช้ PascalCase | ชื่อของ React component ควรเริ่มต้นด้วยตัวพิมพ์ใหญ่ | MyComponent , UserProfile |
File Names | ใช้ PascalCase หรือ kebab-case | ชื่อไฟล์ของ component ควรตรงกับชื่อ component | MyComponent.js , user-profile.js |
Function Names | ใช้ camelCase | ชื่อฟังก์ชันที่ไม่ใช่ component ควรเริ่มต้นด้วยตัวพิมพ์เล็ก | handleClick , fetchData |
Props | ใช้ camelCase | ชื่อ props ควรใช้ camelCase | userName , isLoggedIn |
State Variables | ใช้ camelCase | ชื่อของ state variables ควรใช้ camelCase | isLoggedIn , currentUser |
Event Handlers | ใช้ prefix handle | ควรตั้งชื่อฟังก์ชันที่จัดการเหตุการณ์โดยใช้ prefix handle | handleSubmit , handleChange |
Boolean Props | ใช้ prefix is หรือ has | ชื่อ props ที่เป็น Boolean ควรเริ่มต้นด้วย is หรือ has | isVisible , hasError |
Constants | ใช้ UPPER_SNAKE_CASE | ค่าคงที่ควรใช้ตัวพิมพ์ใหญ่และเชื่อมด้วย _ | MAX_COUNT , DEFAULT_TIMEOUT |
Context | ใช้ PascalCase ตามด้วย Context | ควรตั้งชื่อ context ให้บ่งบอกถึงความหมาย | UserContext , ThemeContext |