Comments (9)
I don't think your proposed solution is right though. I think we should rather extend UndefinedInitialDataOptions
When looking at the types more closely I believe you are correct.
According to my understanding the idea is that UndefinedInitialDataOptions
will return query result where data
is possibly undefined, while DefinedInitialDataOptions
returns query result where the data
is required, so the consumer wouldn't need to handle the optional undefined
value. According to that logic the option of () => T | undefined
can result in a query that is possibly undefined, so it should be in the UndefinedInitlaDataOptions
(Even though it's confusing, because the initialData
is technically "defined").
I'll fix the PR accordingly.
from query.
okay interestingly, we have test that cover this case already, and they don't fail:
It doesn't fail because you use useQuery
directly. The bug (both in angular and react) reproduces when you use queryOptions
from query.
Opened a PR that fixes this: #7351
from query.
Hi @TkDodo I'm not sure about this one. Code is identical to React adapter and I don't think initialData is supposed to be able to undefined?
from query.
The problematic types are defined in angular-query-experimental.
If an undefined return type is not supported than I'm not sure how the common use case will work. This example (from the docs) currently wouldn't work:
result = injectQuery(() => ({
queryKey: ['todo', this.todoId()],
queryFn: () => fetch('/todos'),
initialData: () => {
// Use a todo from the 'todos' query as the initial data for this todo query
return this.queryClient
.getQueryData(['todos'])
?.find((d) => d.id === this.todoId())
},
}))
Also, this works in react-query:
const x = useQuery({
initialData: () => undefined,
})
from query.
it should work, but it also doesn't work in react query:
I don't think your proposed solution is right though. I think we should rather extend UndefinedInitialDataOptions
to be:
export type UndefinedInitialDataOptions<
TQueryFnData = unknown,
TError = DefaultError,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
- initialData?: undefined
- initialData?: undefined | () => undefined
}
thoughts ?
from query.
sorry, that doesn't work. This seems to be the correct diff:
- initialData?: undefined
+ initialData?: undefined | InitialDataFunction<TQueryFnData>
from query.
okay interestingly, we have test that cover this case already, and they don't fail:
query/packages/react-query/src/__tests__/useQuery.test-d.tsx
Lines 79 to 91 in 39b2f81
🤔
from query.
I fixed the PR per feedback: #7351
from query.
Related Issues (20)
- Docs website doesn't work in Brave HOT 2
- Docs website is down HOT 3
- Docs: Error on migration guides HOT 1
- queryFn with server action name not working on Next.js HOT 1
- isLoading does not exist on useMutation @tanstack/vue-query
- Docs: Invalid links in quick-start.md
- Query not updating when Set used in query key HOT 1
- Vue Query + Nuxt 3 SSG - Can not reset hydrated query HOT 2
- Entire website is down HOT 1
- eslint plugin: false positive for function calls HOT 4
- The query status does not change when the query is activated after being inactive despite executing queryFn HOT 1
- Allow to pass nonce to ReactQueryStreamedHydration HOT 1
- TypeError: Cannot assign to read only property '0' of object '[object Array]' HOT 2
- In the underlying code, pages in the getNextPageParam method in infiniteQueryBehavior is undefined. HOT 1
- pages in the getNextPageParam method in infiniteQueryBehavior is undefined. HOT 3
- [Vue]: skipToken example is misleading
- queryOptions is not in @tanstack/react-query HOT 1
- Handling Offline Mutations Persistently Across App Restarts in React Query v5 HOT 2
- eslint-plugin-query: @tanstack/query/exhaustive-deps is triggered for a type used in an instanceof call. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from query.