How can I use the `keepPreviousData` flag in React...
# react
h
How can I use the
keepPreviousData
flag in React Query’s
useQuery
through
placeHolderData
? Through the kotlin-wrappers the former is defined as
external fun <T> keepPreviousData(previousData: T?): T?
and the latter as
Any
, with some types commented out. Library docs: Tanstack Query docs I’m using wrappers-bom:1.0.0-pre.668.
t
Copy code
placeholderData = ::keepPreviousData
Works?
h
Nice, but how can I pass type parameter?
Not enough information to infer type variable T
t
Copy code
::<T>keepPreviousData
?
h
That yields compilation errors
Expecting an identifier
and
Type arguments are not allowed
I tried wrapping the generated function like this:
Copy code
fun wrapperFunc(previousData: GroupedResponse<Show>?):GroupedResponse<Show>? = keepPreviousData(previousData)
and then doing
placeholderData = ::wrapperFunc
. This compiles, but does not yield the expected behaviour
I also tried following the options described here, both through a val and a fun: `
Copy code
val placeholderDataVal: (previousData: GroupedResponse<Show>?, previousQuery: Any?) -> GroupedResponse<Show>? = { previousData, _ -> previousData }

with
placeholderData = placeholderDataVal
and
Copy code
fun placeholderDataFunc(previousData:  GroupedResponse<Show>?, previousQuery: Any?):  GroupedResponse<Show>? = previousData

with
placeholderData = ::placeholderDataFunc
. Same as above: Compiles but not obtaining desired functionality
t
Looks like bug 😞
h
I’ll look into it, thank you for helping!
t
They have fine codesandbox templates in docs for fast test case creation.
👍 1