N
N
Nick Bukovskiy2020-05-13 19:52:51
redux
Nick Bukovskiy, 2020-05-13 19:52:51

How to get data from server on first visit to site and write to redux store?

I use React, Redux, Thunk, Router

For the route I use a method for lazy page loading.

On one of the pages, on the first visit, I need to take the data from the server and write it to the redux store, and then just reuse it. I want to receive data through redux-thunk Tell me how to do

it right? The approach itself? I will be very grateful

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2020-05-13
@Extar93

I would do this: in the didComponentMount hook, dispatch a request that will take data from the server. You can check it through a cookie or localstorage, after the first time write something like dataLoaded into cookies and check before the request, if there are no cookies - we pull, if there are - we don’t pull and use what is saved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question