skip to Main Content

Data usage really matters for my targeted users. So, I am looking for an APPROACH that’ll help me reduce the number of data fetching during react rerender cycles in React and React-native App.

Let’s say I have a page that renders all the Items fetched from an API. Since the API’s data can be updated at anytime, I am obliged to re-call the API whenever the user displays this page.

IS THERE ANY WAY FOR ME TO KNOW THAT THE DATA HAS BEEN UPDATED WITHOUT BEING OBIGED TO RECALL THE API?? Because I think that the less HTTP requests I send the less mobile data I consume (Maybe I am wrong… I don’t know)

I thought of implementing a solution with Redux and Socket.io :
I wanted to prepare an event called data-updated that will be managed by socket.io and whenever one of the users performs an action that updates the item lits (The API data), the data-updated event will be triggered and all the connected users will be notified. Then in the data-updated event handler I will update the item list state slice in the redux store.

My worry is that since socke.io keeps the connection between users and the server alive during the whole session, Won’t this approach consume even more Mobile data than recalling the server at any rendering??

2

Answers


  1. You can proceed with graphql with mutations and its caching mechanism, its pretty cool and if I mention if it is handled efficiently you can run your application in 2g network also with speed. Checkout its usage and advantages over REST you gonna love it. https://graphql.org/

    Another way is by using redisCache but personally I’ve not used it though you can check.

    Login or Signup to reply.
  2. You can use React-query lib for data fetching, updating, caching etc.you can read more about it but read its docs.

    https://tanstack.com/query/v4/?from=reactQueryV3&original=https://react-query-v3.tanstack.com/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search