F
F
Fanil Zubairov2020-09-02 21:18:55
React
Fanil Zubairov, 2020-09-02 21:18:55

Best practice for preloading a list?

A little tricky application, but the essence is this:
* users are displayed on the root page: 5f4fe01c2e7d1206649462.png
* on the post page - post + comments: 5f4fe06ef20ba437097881.png
I use dumb components to display + containers for them to map the state, for example, for users: 5f4fe0bf7757e442360325.png
As you can see in the example, there is an action for fetching data (for users fetchUsers, for comments - fetchComments, etc.). Loading is performed automatically, without a user click, upon hitting the corresponding page, ideally, the data should be preloaded.

Actually the question is: Where to dispatch these actions: in the display component, in the App or in some other component (for example, DataFetcher) - where do we load based on the url in the router?
Share your experience)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kulakov, 2020-09-02
@fannisco

Dispatch in the parent component, so that the data is preloaded before the place where it will be used, if you need it when the application is initialized, then dispatch in App.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question