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

Released under the MIT License