Can I add a listener or a trigger to AsyncStorage?

Viewed 1193

I am currently writing react-native for a Chat feature for my app.

I am using Firebase as the mailBox. Since I don't want to save chat data on our database, I decided to save messages to the AsyncStorage, the device database.

So, the steps are like this:

1) User B's device listening to his mailBox changes on Firebase

2) User A send message to User B mailBox on Firebase

3) User B received the new message, because of Firebase listener

4) User B's device save the new message to AsyncStorage

5) User B's device detected changes on AsyncStorage and update the UI of Chat

Come to here, I need a listener to listen to the AsyncStorage changes so that the UI can be updated accordingly.

This come to the topic: Can I add listener or a trigger, like DB trigger in Oracle database, to AsyncStorage?

Also, I would also like to know whether I should save users' messages in my server database. Thanks

1 Answers

I am not sure about the listener for async storage but a good alternative to your problem would be redux.

You can use redux for this purpose. Update the redux with the result when you are updating the Async Storage.

  • Make a common function that syncs your async storage and redux both. So whenever you make any change in async storage that will automatically get synced in redux as well.
  • Just connect the component with the redux state.
  • So as changes are synced in redux so the ui will change automatically because your component is connected to redux.
Related