null is passed as pageParam with PersistQueryClientProvider
See original GitHub issueDescribe the bug
Our code uses react-native
, useInfiniteQuery
with PersistQueryClientProvider
:
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 5 * 60 * 1000, // 5 min
cacheTime: 1000 * 60 * 60 * 24, // 24 hours
},
},
});
export function CustomQueryClientProvider({ children }: { children: ReactNode }) {
return (
<PersistQueryClientProvider
client={queryClient}
persistOptions={{ persister: asyncStoragePersister }}
onSuccess={() => {
// resume mutations after initial restore from the storage was successful
queryClient.resumePausedMutations();
}}
>
{children}
</PersistQueryClientProvider>
);
}
type MovesQueryKeyType = [string, GetMovesFilter | undefined];
type MovesQueryOptions = UseInfiniteQueryOptions<MovesData, unknown, MovesData, MovesData, MovesQueryKeyType>;
type MovesQueryFunctionContext = QueryFunctionContext<MovesQueryKeyType, number>;
export const useMovesQuery = (filter?: GetMovesFilter, options?: MovesQueryOptions) =>
useInfiniteQuery(
[MOVE_QUERY_KEY, filter],
({ signal, pageParam }: MovesQueryFunctionContext) => getMoves(filter, pageParam, signal),
{
...options,
getNextPageParam: (_, pages) => pages.length + 1,
}
);
const { isLoading, data: movesData } = useMovesQuery(undefined, {
staleTime: 0,
});
According to the type system pageParam
passed to getMoves
is a number | undefined
. But when I re-run my app null
is passed as pageParam
Your minimal, reproducible example
in description
Steps to reproduce
- Open app, load first page of the infinite query
- Reopen app to allow
PersistQueryClientProvider
to restore persisted cache
Expected behavior
null
should not be passed as pageParam
according to the types
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Expo Go on Android
react-query version
4.10.1
TypeScript version
latest
Additional context
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9
Top Results From Across the Web
Can I pass null as a query key? · Discussion #2011 - GitHub
I use SWR and I'm considering switching to React Query. Basically everything about react-query seems better so far, except one: null / error ......
Read more >React query infinite scroll pageParams is undefined
for the first page, the cursor will be set to 0 , as pageParam is undefined . So it's just up to you...
Read more >How to Handle null values when passing nothing in Single ...
In this post we will see how to handle NULL input (-- input value in single select parameter) in single select parameter. i.e.,...
Read more >Passing nulls to Named Query when testing - Ignition
I have an SQL table which has nullable numerical fields (and none of the fields have default values) , and I want to...
Read more >SQL ignore part of WHERE if parameter is null - OutSystems
I'm trying an SQL query where I pass a parameter (MovieID). This parameter has an Identifier Type. This parameter may be empty. What...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We’ve discussed this and there doesn’t seem to be a good way that wouldn’t break some edge cases where people rely on
null
being rightfully returned fromgetNextPageParam
.We have a plan that disallows
null
being returned from there, then we can treatnull
likeundefined
and side-step that issue. We would make sure internally that you’d always getundefined
passed into the queryFn even ifnull
sneaks into thepageParams
.But, it will have to wait a bit for the next major release.
The problem is that
pageParams
will likely have multiple entries, so it’s:there is no real way to serialize this to json and keep the information that there was an entry.
superjson supports serializing undefined, so you might just want to use this as a drop-in replacement for JSON.stringify / JSON.parse