V
V
Vann Damm2021-01-18 16:02:29
React
Vann Damm, 2021-01-18 16:02:29

How to draw the data in this case?

There is data that I get from the server depending on the url. The difference between these data is only in their date of creation. i.e. when you click on the button - I get yesterday's data, on the second button - today's, on the third - future. I sort the data by date on the back. i.e. for each url its own controller is obtained. The problem is that when I click on the "today" button, I need to display data for today (separating them by title) and for yesterday, respectively, when clicking on "yesterdays", for yesterday and for today. The question is how to do it? 1. Get data by url for example /today , thus: two arrays of data sorted (today and yesterday), set them to the store and render. 2. Get them all in one go (today, yesterday, future), sort at the front and when switching on different urls just take data from the store? without requests to the back. How to be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander199, 2021-01-18
@Alexandr199

For me, it is better to separately make requests for today and yesterday. After all, this is the essence of React, that each component should only call those requests whose data it needs.
Why make a request for everything, if a person may not even click on these buttons at all, in total you just have an extra request and extra data.

D
Denioo, 2021-01-18
@Denioo

Use the flux methodology for this, the most common implementation in react is Redux or you can do it with useContext, useReducer hooks.
How it works: you have a shared storage where you add today's and tomorrow's data when making requests.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question