My Authors
Read all threads
@acdlite Has this been elaborated anywhere? I'm trying to see what the rules are for mutating refs within a data-fetching hook. CM interrupting renders + data-fetching asynchrony makes this ... hard.

My worry is something like the following:

1/
@acdlite useQuery hook called, "currentQuery" ref is updated

render is interrupted

Can that same render be re-run but...with older state? That's not possible, is it? Except with useTransition, but in that case the new-state renders / old-state renders are in separate trees?

2/
@acdlite Ever be humanly possible for:

useQuery existing w/ data for query "A"

useQuery called with query "B"

currentQuery.current set to "B"—fetch()

useQuery re-renders w/ old query state "A"

ref set to "A"

promise for "B" resolves—wrongly thinks it's outdated bc mismatching ref
@acdlite To be clear, the user purposefully switched from query A to B, and that's it. The user never went "back" to A.

I'm just trying to nail down whether it's safe for a ref in a data fetching hook to maintain a ref to that updated value, or if CM will jack that assumption up.

/N
@acdlite Oh ... or ... should the resolving promise just update the cache, and then force a re-render, ie setJunk(x => x + 1), and rely on React to know what the right state is?
@acdlite Or maybe I should ask @dan_abramov since he’s rocking an AMA on Twitter today
Missing some Tweet in this thread? You can try to force a refresh.

Keep Current with Adam Rackis

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!