Closed jaredpalmer closed 6 years ago
Can use async, await function when loop visit component tree?
async/await is just syntax sugar for promises, so in theory it should work fine.
edit: with v2
@jonjaques see the newly released API, also react-async-bootstrapper
for an example implementation.
@ctrlplusb Ooohhh, does that work like I think it does too? AKA it's fully recursive?
Yep :)
Here's my crack at it — One issue I'm currently trying to wrap my head around is how to block on or access nodes that conditionally include further
fetch()
components. As it currently stands, this code will never pick them up. Also, haven't gotten to solving this on the client side yet.@jaredpalmer I realize this doesn't necessarily help with React Router, but for me this is the same problem. Once I figure out how to actually recursively call these promises, I think it's just a matter of hooking into router's transition manager and delay based on the
resolve
promise.To illustrate the problem here is an example (I'm hoping @ctrlplusb will have an idea 😄 ):
So I think the problem is that the props are never propagated back down the tree. In my logging,
App.props.data
never changes value, even after thefetch()
is resolved.The two lines I've commented out were trying to play around with pausing walking to wait for a promise as suggested in the README, though things still don't seem to pan out.
I've also tried reinstantiating the whole tree and walking from the top - however that has it's own issues such as hitting the same promises again. However, I kind of wonder if that's what is going to be necessary - and I need to figure out some way to mark them as resolved for further walking?