แสดงบทความที่มีป้ายกำกับ React Native แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ React Native แสดงบทความทั้งหมด

วันเสาร์ที่ 31 ตุลาคม พ.ศ. 2563

[React Native] Redux

Redux

- ใช้แชร์ State แบบ Global ให้ทุก Component เข้าถึงได้
- Component ต้องเรียกใช้ Action ในการแก้ไขข้อมูลใน State Global โดยตรง
- ใช้ Logger ในการ Track ได้จะเห็น prev state, action, next state

npm install redux redux-logger redux-thunk react-redux

redux react-redux : ลง redux และใช้ react-redux
redux-logger : ใช้ track การเปลี่ยนแปลงข้อมูล
redux-thunk : เพื่อให้ใช้งาน asynchronous ได้

Flow

graph LR; a([State])--defines-->b([UI]); b([UI])--triggers-->c([Actions]); c([Actions])--sent to-->d([Reducer]); d([Reducer])--updates-->e([Store]); e([Store])--contains-->a([State]);