0

Quick question regarding a react + redux front-end for a social media application that queries for new posts frequently, and therefore updates the back-end database frequently. The user on the front-end gets to approve or block the posts as they come in.

What is a good timeline/process for keeping the redux store matched up with the back-end database?

Would the front-end regularly query for any new posts in the backend, load them into the redux store, then when the user hits 'approve' for a post, a request is sent to the back-end, and if 200 OK, update the redux store?

Thanks.

flq
  • 22,247
  • 8
  • 55
  • 77
haybales
  • 15
  • 1
  • 6
  • 1
    Socket.IO enables real-time, bidirectional and event-based communication. https://socket.io – wdm Oct 03 '18 at 17:58
  • even with socket.io as the communication medium, to what degree would I sync up the back-end DB to the redux store? Would I put the complete list of approved posts on a separate static page, or pull all that data into the store? – haybales Oct 03 '18 at 18:37
  • The front-end would initially query for `n` number of results. At this point the socket would wait for new results and send them to the front-end as they come in. If you're storing an array of posts in the redux store you can append to that array. – wdm Oct 03 '18 at 18:55
  • the redux store is just for whatever the client sees.. there's no magic amount of syncing.. you only need to sync whatever you want the user to see – azium Oct 03 '18 at 19:27
  • 1
    Oh I see. I think what I'm looking for is pagination of these posts so what's stored in the redux store doesn't get too big. – haybales Oct 03 '18 at 19:53
  • I suppose that once sth is approved or rejected you can remove it from the redux store. Also, if the user of the app can't cope with the incoming posts, throttling could be an idea. Keep something like an ETag and pause the filling of the store, later on you can resume with that ETag to pull those that the user hasn't seen yet – flq Oct 03 '18 at 19:56

0 Answers0