จับคู่เครื่องมือกับ ประเภท ของ state มากกว่าการหยุดไปยัง global store โดยค่าเริ่มต้น ปัญหา "global state" ส่วนใหญ่เป็นเครื่องมือที่ผิดสำหรับงาน
คำแนะนำการตัดสินใจ
text
Local UI state (toggle, input) → useState / useReducer
Shared, low-frequency (theme, user) → Context
Server/API data → React Query / SWR (NOT a global store)
Complex global client state → Zustand / Jotai / Redux Toolkit
URL-shareable state (filters, page) → the URL (search params)
Insight ที่สำคัญที่สุด: server state ≠ client state
ข้อมูลจาก API คือ cache ของข้อมูลระยะไกล ไม่ใช่ state ที่คุณเป็นเจ้าของ การใส่ลงใน Redux หมายความว่าคุณต้องจัดการ loading, caching, refetching และ invalidation ด้วยตนเอง — เจ็บปวดและเสี่ยงต่อข้อผิดพลาด ไลบรารี server-state ทำทั้งหมด:
