How should I update redux store during a react-router transition?

后端 未结 2 2030
挽巷
挽巷 2021-02-15 02:35

I\'m facing an issue on how to update store when a react-router transition occurs.

In my current implementation (below), update store before rendering next page. The iss

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-15 03:30

    One solution would be to make your pages compatible with having incomplete data, until the new page data is fetched. Then you could push the new path, and it would render immediately as much as it could, and your UI components render spinners (or something equivalent) until the data for the next page is fetched and dispatched to the store. On the second pass, the page would be re-rendered fully.

    The other thing that comes to mind is that ideally, the shape of your store is such that all your pages are fundamentally compatible with all possible states that it could be in, without conflict. That will let you do things like prefetching data, which could unlock ways to minimize transition time, and to cache previous views. After all, single-page architecture isn't especially useful when it still requires a round-trip.

提交回复
热议问题