Skip to content

What's the behaviour of defer and why should I use it? #10538

Answered by brophdawg11
WorldSEnder asked this question in Q&A
Discussion options

You must be logged in to vote

The underlying technical difference is largely negligible and you can mostly just ignore defer in React Router client-side only SPA's. It's required in Remix (until the single fetch feature lands) as a way to tell us that we need to serialize a promise over the wire - but in RR SPA's there's no "over the wire" so a raw promise works just fine.

Basically, the functional difference is that defer wraps the promises so that if they resolve before we render, we can avoid an unnecessary additional render pass.

With a raw promise, at render time we have no way to know if the promise has already been resolved, so when your component renders we have to hook onto .then and throw data.users from Await

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@johot
Comment options

Answer selected by WorldSEnder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants