Answer the question
In order to leave comments, you need to log in
When is mapStateToProps ready?
Hello,
I have an array of some elements in the store. For each of them, I need to call an asynchronous function in the component - let's assume that this is an array of wallet addresses, and for each I need to call getBalance.
The problem is that at the `componentDidMount()` stage, the desired array is still empty. Using `componentWillReceiveProps()` is also not cool - something is constantly changing in the component, and you don’t need to pull the server every time, you only need to once.
How do you usually act in such situations? Thank you.
Answer the question
In order to leave comments, you need to log in
How do you usually act in such situations?
option: make a WalletsContainer component, in which an array of wallets is passed (first empty, and then already filled, and all without additional checks, just new props came), in which each wallet is checked by a request (via promise.all in the action) and in As a result, at the end of the checks of everything that is needed, an update is called in the store. Or updates in the store are called asynchronously, updating only the required wallet (the request for the balance of which has ended). If you need to interact with the parent, either you pass the functions, or you use redux further.
Another option: "We'll have to fence some garbage with a counter, it seems that it only works the first time." just no bullshit. See if the wallets were empty, but it became thick - update and make any requests you need. If not, this "if" skips and nothing happens.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question