How to wait for data in reduction

For example, I have 2 components. In the 1st, I make an asynchronous call on the server and after sending, to send a response to the redux repository. In component 2, I want to wait for an answer to be received, and after some work.

1st component looks like

const response = await api.call(); // async call on server
dispatch(putToTheStore(response)); // put data to the store

The second component looks like

await props.response; // here i want to wait data come to store

// and after it actually come to the store, do some work

Is it possible?

+4
source share
1 answer

If you connect your second component to the repository using the function react-redux connect, you do not need to do anything to update the component. Data added to the repository will simply be available for the component as prop.

() , . , mapStateToProps, , , props .

, , componentWillReceiveProps.

+4

Source: https://habr.com/ru/post/1681624/


All Articles