Replies: 1 comment 4 replies
-
For what you described, instead of using startTransition, use Note useDeferredValue is integrated with . If the background update caused by a new value suspends the UI, the user will not see the fallback. They will see the old deferred value until the data loads. To check if the transition is pending (as there will be no fallback by Suspense boundary), compare deferred and non-deferred query key references (when finished loading, deferred and non-deferred querykeys will be ref equal) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey team. I'd like raise that
startTransition
with useSuspenseQuery is generally a less useful API compared touseQuery
withplaceholderData: keepPreviousData
, and petition to add back the ability to keep previous data while fetching without needing to wrap updates instartTransition
.The big pain point is that using
startTransition
requires very specific abstractions over fetching, either every consumer of auseFoo
hook needs to decide how to handle all updates or state updates that triggers updates need to live very close to the fetch call site. The simple example is something like:Behaviorally this does what I want, suspend on initial fetch, and show data while fetching the next page or updating the list filters. HOWEVER, it's really limited in the abstraction I can provide consumers. In real cases, we'd need to control and hoist
filters
so that a toolbar above the table showing the list can adjust the shown todos. In order to hoist this out i'd have to:usePagedTodos
hook to a common parent.filters
as an inputusePagedTodos
and tell users wrap their updates in a startTransitionThe first option isn't ideal, it forces a higher suspense boundary than you might want and requires that data retrieval be done very high up vs close to the component consuming the result. The second option isn't great either b/c it's super leaky, and requires either a second utility like
useTodosFilters
or discipline on consumers to get behavior correct which they shouldn't have to think about. BOTH approaches conflate "filter updates" with "don't suspend" which isn't flexible or correct. I may not care if other areas of UI to suspend in response to a filter change, just not query hook.In contrast the
useQuery
version of this keeps behavior configuration internal to the hook that returns the data which is i'd argue is what you want. A really nice aspect of RQ's hooks is that they are really idiomatic hooks, in that input changes trigger updates allowing for flexibly decoupled abstractions and usages.startTransition
OTOH requires structuring things in terms of imperative calls to fetch, e.g. wrap and returnfetchNext
. There is a really nice simplicity to this example that isn't possible with suspenseBeta Was this translation helpful? Give feedback.
All reactions