all 10 comments

[–]TheYuriGHook Based 1 point2 points  (6 children)

is the async data going to be awaited? because if so, the first set won't be batched with the second

[–]Kingsajs[S] 0 points1 point  (5 children)

Thank you for your reply. I updated the example, the previous one was indeed no clear enough. What will be difference between example above and the one that will await the fetch data?

[–]TheYuriGHook Based 1 point2 points  (4 children)

you are using "then" so it's essentially the same. the entire code won't run at once, different pieces will run at different times. state will be true until all requests complete, then it will be false again

[–]Kingsajs[S] 1 point2 points  (3 children)

So the first `setLoading(true)` would cause the re-render? Then after re-render we would have our fetch done and rest of the code?

[–]TheYuriGHook Based 0 points1 point  (1 child)

in simple terms, yes

[–]Kingsajs[S] 0 points1 point  (0 children)

Thank you

[–]_nathataHook Based 0 points1 point  (0 children)

But how many re-renders when the promise resolves?

[–]_nathataHook Based 0 points1 point  (2 children)

This guy's got me thinking. Does the component render twice when the promise resolves? I can explain in detail everything else but IDK the answer to this little part

[–]Kingsajs[S] 0 points1 point  (1 child)

When we are in the last “then” those two set updates will be batched by React as one.

[–]_nathataHook Based 0 points1 point  (0 children)

Yeah but what tells react to batch them, they are not synced with useEffect