Should I build a local data layer/app state to maintain state in a React Native/Firestore App?

前端 未结 2 445
遇见更好的自我
遇见更好的自我 2021-01-21 21:03

A main selling point of Firestore is the ability to use it as a online/offline source of truth. I\'m using it in this way right now: updating the Firestore document directly on

2条回答
  •  没有蜡笔的小新
    2021-01-21 21:18

    This not an answer, just a long comment :)

    @learningAngular For example, in toggleNotifications just need to call an async action creator and don't worry about putting any logic inside react component.

    Instead Redux pattern gives space to do some logics, in this case because user's last moment decision is source of truth so dispatch function would always set a local tempState and updatingStatus before start updating firestore, then after firestore promise either resolved or rejected dispatches an action to reducer to reset updatingStatus. Then a selector would check if updatingStatus is true to just rely on local tempState otherwise rely on listened firestore state. Finally, react component use selector result as currently valid state.

    I am not answering this question because I don't have that much experience. I am also curious if a good solution is out there, but this is what I think is the solution at this moment.

提交回复
热议问题