1

I have loaded my data in a react native component, however, the same data can be changed by another user in another app. What is the best way of telling the other app (component) of the data change to refresh? I am looking for something quick and easy.

  1. Is it push notifications?
  2. Opening a web socket with the server for data changes?
  3. Any other standard followed?
doublevision
  • 101
  • 2
  • 10
  • You should use socket in order to communicate the changes. – Usama Moin Dec 29 '19 at 02:07
  • 1
    Use of Firebase realtime database will solve your problem if the amount of dataset is huge else you can use a web socket if the amount and scope of change is less. Use of push notifications in this case is not a good solution. – Parvej Mallick Dec 29 '19 at 06:25

1 Answers1

0

Edit: This likely is the best solution assuming you are using react-redux to maintain application state:How to refresh a react redux application when data changes on DB outside of the application

Your question does require some clarification because if you are sending data across components, then you don't need to do any of the above, you change the state of the component and react should update the view. You also need to provide more details on whether you are sending data from child component to child component or from parent component to child component or from child component to parent component so that I can point you to the appropriate stackoverflow question.

See: Send data from child to parent React Or: How to share data between non parent-child react components?

If you are wanting to send data across two different applications,

Are you using react redux at all to maintain app state or are you using react's built in state management? If you are using react redux and redux-persist, I'd recommend applying a middleware that handles changes to state and using a server-side data store and building sync operations. Does the data need to update in realtime in your other application and is that application also another mobile application in react native? Do you anticipate users utilizing the same application across different devices? Push notifications should only be used for notifying users. The approach I would use is to use a pouch-db redux-persist adapter and sync state that way so that whether your app runs on mobile, web, etc, the state syncs across devices. If its the same data but for different users, this can still work but don't couple the reducer for the data that isn't specific for a user to the user.

See: https://github.com/rt2zz/redux-persist

Scroll to the bottom to see DB engines available for redux-persist

See: https://pouchdb.com/

  • Backend server = Rest APIs (Spring boot+mysql) It seems redux is for state management within the app, not my case. The data is changing between the two apps. E.g a buyer needs to buy an item from a seller, now the seller needs to know the buy request. There are a couple of ways to do this. 1. All the apps can poll the rest API to pull the latest state from the server after an interval. 2. The server can create an event and all consumers can subscribe to that event, as the request will be made all consumers will know the change event and pull the latest. What is the standard? – doublevision Dec 29 '19 at 07:50
  • I do not have much experience with spring boot but generally it seems the second route you described seems to make more sense and seems to be more reliable especially in scenarios where exchange of currency is involved. I would not rely on making unnecessary calls to the API based on an interval because it can result in errors if there is a chance of inconsistent state between server and client. Example: Buyer 1 request is sent to server and seller's app refreshes based on interval, but buyer 2's app still shows item as available and sends buyer request. Seller only see's 1st buyer request. – Rohit Keshwani Jan 02 '20 at 00:00