* fix(types): handle useQueries wrappers with strongly-typed array parameters
* test(types): confirm typecheck passes without explicit type for mapped query
* test(types): add typecheck on queryFn in mapped query
* refactor(useQueries) export QueriesOptions type
export the QueriesOptions type
closes#3250
* refactor(useQueries): add export to index
Add the export of the QueriesOptions type to the index file
* refactor(useQueries) export QueriesResults type
Export QueriesResults type
Co-authored-by: Jeffrey Sims <jeffreysims@Jeffrey-Sims-Mac.local>
On the first rendering, `hasNextPage` is `undefined`, but converted to `true` by the default value.
For intersection observer to trigger correctly without clicking more button, `hasNextPage` needs type casting.
incrementing and decrementing transactions need to happen in an atomic operation, no matter what happens in between; if we increment, but never decrement, we will get to a state where transactions can never become zero - we're basically "leaking" an open transaction. This leads to no observers being informed ever again because we think we still have an open transaction
this can be fixed by using try/finally to always decrement the transactions
* examples: react-native
Same example as in the Expo snack but in Typescript
* docs(examples): react-native: add link to the typescript version in the repo
* fix: use proper type for onAppStateChange
not all runs to createResult are saved on `this.currentResult` (optimistically created updates do not - we just create the result again later). With the fix from #3098, we made sure that memoized select does not run again in those cases by storing every run. However, that now means that we cannot rely on `prevResult.data` because it might still contain outdated data.
The solution is to store a pair of previous selectFn + data and return the exact data that was computed from the previous select fn if we get the exact same function passed
we compute the result optimistically, and then one more time when calling setOptions. Both times run the select function because only setOptions will update the previous result and previous options. storing the "previous" selectFn separately on the observer whenever it was invoked (independent of the fact from where it was called) side-steps the issue
* fix(useInfiniteQuery): fix infinite re-renders when select produced a new result
by correctly forwarding notifyOptions
* fix(useInfiniteQuery): fix suspense test
asserting the length of 3 seems wrong here and was likely only necessary because we triggered one too many re-renders before this fix :)
* fix(queriesObserver): fix getOptimisticResult call
Fix queriesObserver to call getOptimisticResult as before.
This was a bug introduced in PR #2866
* fix(queriesObserver): return observers in same order as queries
Sort returned observer entries to match the order of queries.
Previously, with keepPreviousData: true, the repurposed observers
would be returned last, potentially in different order than the queries.
* docs: add React Native code examples for common use cases
- Online status management
- Refetch on App focus
- Refresh on Screen focus
* docs(react-native): use useOnlineManager example
* fix(useQuery): continue retries if observer unmount and remount
if we are waiting for a retry to happen, unsubscribing he last observer will cancel retries and just return the error; however, if a new observer subscribes in the meantime, we should continue with the ongoing retries.
this is especially important with "strict effects" in react18, where effects are run twice and thus observers are always unsubscribed and re-subscribed immediately.
* fix(useQuery): continue retries if observer unmount and remount
add another test to include query cancellation
* fix(useQuery): cleanup queries even if they have been fetching
* fix(useQuery): cleanup queries even if they have been fetching
do not re-schedule garbage collection if a query is fetching and we never had any observers subscribed; this is necessary to make suspense work, because with suspense, we always throw before we subscribe, so the garbage collection would prematurely remove the query, resulting in an infinite loop
* fix(useQuery): cleanup queries even if they have been fetching
only schedule garbage collection when the last observer unsubscribes rather than in the constructor
this works around the suspense issue because we only add observers after we've loaded as we throw before that.
if you useErrorBoundary, you're likely not observing the error, because you're not using the returned error field - the ErrorBoundary handles the error for you. So when the actual error then happens, we don't inform the observer about it, because we're only informing them if a prop has changed that they are interested in, resulting in the error boundary never being shown.
The solution would be to always track the error property if you've set useErrorBoundary