Content
@
0 reply
0 recast
0 reaction
Robotandkid
@robotandkid
q: Can you make network calls directly in the React render function? IMO, the network call itself won't degrade performance. (It'll just get put on the async queue so won't block rendering). However, it's not best practice because there's stuff that's harder to do now (ex: fetch only once, canceling the request).
1 reply
0 recast
2 reactions
Charlie
@charliewilco
isn't this what use() is for? https://react.dev/reference/react/use
2 replies
0 recast
0 reaction
Robotandkid
@robotandkid
oh wow use is pretty nice. back to my original question though, this is preferred to doing this yourself
2 replies
0 recast
0 reaction
Charlie
@charliewilco
0 reply
0 recast
1 reaction
Charlie
@charliewilco
i think you should throw the promise in the render method and kinda make your own. you'd wrap the parent in suspense though. i think the problem with using an async function in your render method is that you can't cancel it and it might call setState on a component that might not exist anymore.
0 reply
0 recast
0 reaction