W
W
WeReng2019-07-26 19:23:34
RESTful API
WeReng, 2019-07-26 19:23:34

How to properly receive data from the server in SPA (React + Redux)?

Hello!
There is a single page application on React + Redux + React router. There was a question how it is correct to organize communication with the server.
I will describe the case:
The user opens a page with an application, an API request is made and the necessary data for the page is requested, then the user navigates to another page, where another API request is made and the data for the second page is loaded, and then the user returns to one page back, where earlier we have already downloaded data from the server, what to do in this case? Are we making a second request to the API, or can we take previously loaded data from the Redux Store?
I would like to understand how to properly organize the request logic, is it right to use the Redux Store instead of getting data from the server? Perhaps it is worth caching server responses, using a ServiceWorker, or there are some alternative solutions.
I would be grateful for any information on this matter.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-07-26
@WeReng

what to do in this case?

You should be more visible. If this is data that could change, then it is obvious that it is better to pull up fresh ones. If something that rarely changes, then you can check for availability in the repository.
You can also use a socket connection and implement logic on the server so that it itself sends updates to the client as they appear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question