React multiple components rely on the same data, so how should the data be handled?

such as the title.

because two components are involved, I intend to use redux. The thing is, these two components are not displayed at first, in other words, the data does not need to be loaded by ajax at the beginning, and the data is not loaded until a component is triggered to load. If another subsequent component is also loaded, go directly from the redux.

the logic here is that if the redux has the data, it will be fetched directly, and if not, it will be loaded once from the server. It is not quite understood here, does each redux data have to be divided into three states: loading for the first time, loading, loading completion? It"s a little complicated! How do we deal with things like this?


it seems that the behavior of the two components in terms of data is equivalent, so you should determine the existence of the data in the didmount of the two components, and request if it does not exist.

if there is a possibility that the second component will be loaded before the first component request returns, then the request needs to be throttled.


since you don't need display at first, you just need to get the data when it's triggered and render.

Menu