Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cca39d0
refactor(query-core): remove overloads
Mamoanwar97 Dec 27, 2022
797f2fa
test(query-core): apply single signature to all tests
Mamoanwar97 Dec 27, 2022
54cc996
refactor(react-query): remove overloads
Mamoanwar97 Dec 27, 2022
dd89050
test(react-query): apply single signature to all tests
Mamoanwar97 Dec 27, 2022
85b6824
refactor(solid-query): remove overloads
Mamoanwar97 Dec 27, 2022
184020e
test(solid-query): apply single signature to all tests
Mamoanwar97 Dec 27, 2022
7bff740
refactor(vue-query): remove overloads
Mamoanwar97 Dec 27, 2022
120635a
test(vue-query): apply single signature to all tests
Mamoanwar97 Dec 27, 2022
931d2d0
test(react-query-persist-client): apply single signature to all tests
Mamoanwar97 Dec 27, 2022
d60536f
fix(react-query-devtools): apply single signature to all tests
Mamoanwar97 Dec 27, 2022
055483e
test(react-query-devtools): apply single signature to all tests
Mamoanwar97 Dec 27, 2022
eea1f8b
test(query-sync-storage-persister): apply single signature to all tests
Mamoanwar97 Dec 27, 2022
66f9dfa
docs: apply object single signature to all docs
Mamoanwar97 Dec 27, 2022
9d8cd72
Merge branch 'v5' of https://github.com/TanStack/query into remove-ov…
Mamoanwar97 Dec 27, 2022
c5cc3c2
docs(examples/react): apply object single signature to all examples
Mamoanwar97 Dec 27, 2022
e3c2fbf
docs(examples/solid): apply object single signature to all examples
Mamoanwar97 Dec 27, 2022
41a651a
docs(examples/vue): apply object single signature to all examples
Mamoanwar97 Dec 27, 2022
8568e13
style(examples): run prettier on all files
Mamoanwar97 Dec 27, 2022
807c106
docs: use multiline whenever we use the object syntax
Mamoanwar97 Dec 28, 2022
8a9ae6e
fix(setQueryDefaults): keep it as two arguments
Mamoanwar97 Dec 28, 2022
6630273
fix(createMutation): remove unnecessary shallow copy
Mamoanwar97 Dec 28, 2022
3ffc6ab
fix(vue-query): rename parseArgs functions to unrefArgs
Mamoanwar97 Dec 28, 2022
fcd30e1
docs(migrating-to-react-query-5): list all affected functions
Mamoanwar97 Dec 28, 2022
3346d5a
fix(setQueryData): remove as alias
Mamoanwar97 Dec 28, 2022
cd4a3ae
refactor(getQueryData): getQueryData now supports only queryKey as an…
Mamoanwar97 Dec 29, 2022
c865325
refactor(getQueryState): getQueryState now supports only queryKey as …
Mamoanwar97 Dec 29, 2022
556aedd
test(react-query/useQuery): missing single signature
Mamoanwar97 Dec 29, 2022
7534b46
Merge branch 'v5' into remove-overloads
Mamoanwar97 Dec 30, 2022
2bf7484
Merge branch 'v5' of https://github.com/TanStack/query into remove-ov…
Mamoanwar97 Dec 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions docs/react/adapters/solid-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { Switch, Match, For } from 'solid-js'
const queryClient = new QueryClient()

function Example() {
const query = createQuery(() => ['todos'], fetchTodos)
const query = createQuery({
queryKey: () => ['todos'],
queryFn: fetchTodos
})

return (
<div>
Expand Down Expand Up @@ -69,10 +72,16 @@ Solid Query offers an API similar to React Query, but there are some key differ

```tsx
// ❌ react version
useQuery(["todos", todo], fetchTodos)
useQuery({
queryKey: ["todos", todo],
queryFn: fetchTodos
})

// ✅ solid version
createQuery(() => ["todos", todo()], fetchTodos)
createQuery({
queryKey: () => ["todos", todo()],
queryFn: fetchTodos
})
```

- Suspense works for queries out of the box if you access the query data inside a `<Suspense>` boundary.
Expand All @@ -81,7 +90,11 @@ createQuery(() => ["todos", todo()], fetchTodos)
import { For, Suspense } from 'solid-js'

function Example() {
const query = createQuery(() => ['todos'], fetchTodos)
const query = createQuery({
queryKey: () => ['todos'],
queryFn: fetchTodos
})

return (
<div>
{/* ✅ Will trigger loading fallback, data accessed in a suspense context. */}
Expand Down Expand Up @@ -113,20 +126,21 @@ export default function App() {

function Example() {
// ❌ react version -- supports destructing outside reactive context
// const { isLoading, error, data } = useQuery(['repoData'], () =>
// fetch('https://api.github.com/repos/tannerlinsley/react-query').then(res =>
// const { isLoading, error, data } = useQuery({
// queryKey: ['repoData'], () =>
// queryFn: fetch('https://api.github.com/repos/tannerlinsley/react-query').then(res =>
// res.json()
// )
// )
// })

// ✅ solid version -- does not support destructuring outside reactive context
const query = createQuery(
() => ['repoData'],
() =>
const query = createQuery({
queryKey: () => ['repoData'],
queryFn: () =>
fetch('https://api.github.com/repos/tannerlinsley/react-query').then(
(res) => res.json(),
),
)
})

// ✅ access query properties in JSX reactive context
return (
Expand Down Expand Up @@ -161,7 +175,9 @@ const queryClient = new QueryClient()

function Example() {
const [enabled, setEnabled] = createSignal(false)
const query = createQuery(() => ['todos'], fetchTodos, {
const query = createQuery({
queryKey: () => ['todos'],
queryFn: fetchTodos,
// ❌ passing a signal directly is not reactive
// enabled: enabled(),
Comment on lines +178 to 182
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this workaround is also unnecessary without the overloads. @ardeora can you have a look please


Expand Down
5 changes: 4 additions & 1 deletion docs/react/community/liaoliao666-react-query-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ console.log(usePost.getKey(variables)) // ['/posts', { id: 1 }]
export async function getStaticProps() {
const queryClient = new QueryClient()

await queryClient.prefetchQuery(usePost.getKey(variables), usePost.queryFn)
await queryClient.prefetchQuery({
queryKey: usePost.getKey(variables),
queryFn: usePost.queryFn
})

return {
props: {
Expand Down
90 changes: 90 additions & 0 deletions docs/react/guides/migrating-to-react-query-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,96 @@ title: Migrating to TanStack Query v5

v5 is a major version, so there are some breaking changes to be aware of:

### Supports a single signature, one object

useQuery and friends used to have many overloads in TypeScript - different ways how the function can be invoked. Not only this was tough to maintain, type wise, it also required a runtime check to see which type the first and the second parameter, to correctly create options.

now we only support the object format.

```diff
- useQuery(key, fn, options)
+ useQuery({ queryKey, queryFn, ...options })

- useInfiniteQuery(key, fn, options)
+ useInfiniteQuery({ queryKey, queryFn, ...options })

- useMutation(fn, options)
+ useMutation({ mutationFn, ...options })

- useIsFetching(key, filters)
+ useIsFetching({ queryKey, ...filters })

- useIsMutating(key, filters)
+ useIsMutating({ mutationKey, ...filters })
```

```diff
- queryClient.isFetching(key, filters)
+ queryClient.isFetching({ queryKey, ...filters })

- queryClient.ensureQueryData(key, filters)
+ queryClient.ensureQueryData({ queryKey, ...filters })

- queryClient.getQueriesData(key, filters)
+ queryClient.getQueriesData({ queryKey, ...filters })

- queryClient.setQueriesData(key, updater, filters, options)
+ queryClient.setQueriesData({ queryKey, ...filters }, updater, options)

- queryClient.removeQueries(key, filters)
+ queryClient.removeQueries({ queryKey, ...filters })

- queryClient.resetQueries(key, filters, options)
+ queryClient.resetQueries({ queryKey, ...filters }, options)

- queryClient.cancelQueries(key, filters, options)
+ queryClient.cancelQueries({ queryKey, ...filters }, options)

- queryClient.invalidateQueries(key, filters, options)
+ queryClient.invalidateQueries({ queryKey, ...filters }, options)

- queryClient.refetchQueries(key, filters, options)
+ queryClient.refetchQueries({ queryKey, ...filters }, options)

- queryClient.fetchQuery(key, fn, options)
+ queryClient.fetchQuery({ queryKey, queryFn, ...options })

- queryClient.prefetchQuery(key, fn, options)
+ queryClient.prefetchQuery({ queryKey, queryFn, ...options })

- queryClient.fetchInfiniteQuery(key, fn, options)
+ queryClient.fetchInfiniteQuery({ queryKey, queryFn, ...options })

- queryClient.prefetchInfiniteQuery(key, fn, options)
+ queryClient.prefetchInfiniteQuery({ queryKey, queryFn, ...options })
```

```diff
- queryCache.find(key, filters)
+ queryCache.find({ queryKey, ...filters })

- queryCache.findAll(key, filters)
+ queryCache.findAll({ queryKey, ...filters })
```

### `queryClient.getQueryData` now accepts queryKey only as an Argument

`queryClient.getQueryData` argument is changed to accept only a `queryKey`

```diff
- queryClient.getQueryData(queryKey, filters)
+ queryClient.getQueryData(queryKey)
```

### `queryClient.getQueryState` now accepts queryKey only as an Argument

`queryClient.getQueryState` argument is changed to accept only a `queryKey`

```diff
- queryClient.getQueryState(queryKey, filters)
+ queryClient.getQueryState(queryKey)
```

### The `remove` method has been removed from useQuery

Previously, remove method used to remove the query from the queryCache without informing observers about it. It was best used to remove data imperatively that is no longer needed, e.g. when logging a user out.
Expand Down
6 changes: 3 additions & 3 deletions docs/react/reference/QueryClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const data = queryClient.getQueryData(queryKey)

**Options**

- `filters?: QueryFilters`: [Query Filters](../guides/filters#query-filters)
- `queryKey: QueryKey`: [Query Keys](../guides/query-keys)

**Returns**

Expand Down Expand Up @@ -263,13 +263,13 @@ Updates via `setQueryData` must be performed in an _immuatable_ way. **DO NOT**
`getQueryState` is a synchronous function that can be used to get an existing query's state. If the query does not exist, `undefined` will be returned.

```tsx
const state = queryClient.getQueryState({ queryKey })
const state = queryClient.getQueryState(queryKey)
console.log(state.dataUpdatedAt)
```

**Options**

- `filters?: QueryFilters`: [Query Filters](../guides/filters#query-filters)
- `queryKey: QueryKey`: [Query Keys](../guides/query-keys)

## `queryClient.setQueriesData`

Expand Down
40 changes: 28 additions & 12 deletions docs/solid/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import { Switch, Match, For } from 'solid-js'
const queryClient = new QueryClient()

function Example() {
const query = createQuery(() => ['todos'], fetchTodos)
const query = createQuery({
queryKey: () => ['todos'],
queryFn: fetchTodos
})

return (
<div>
Expand Down Expand Up @@ -70,10 +73,16 @@ Solid Query offers an API similar to React Query, but there are some key differ

```tsx
// ❌ react version
useQuery(["todos", todo], fetchTodos)
useQuery({
queryKey: ["todos", todo],
queryFn: fetchTodos
})

// ✅ solid version
createQuery(() => ["todos", todo()], fetchTodos)
createQuery({
queryKey: () => ["todos", todo()],
queryFn: fetchTodos
})
```

- Suspense works for queries out of the box if you access the query data inside a `<Suspense>` boundary.
Expand All @@ -82,7 +91,11 @@ createQuery(() => ["todos", todo()], fetchTodos)
import { For, Suspense } from 'solid-js'

function Example() {
const query = createQuery(() => ['todos'], fetchTodos)
const query = createQuery({
queryKey: () => ['todos'],
queryFn: fetchTodos
}
)
return (
<div>
{/* ✅ Will trigger loading fallback, data accessed in a suspense context. */}
Expand Down Expand Up @@ -114,20 +127,21 @@ export default function App() {

function Example() {
// ❌ react version -- supports destructing outside reactive context
// const { isLoading, error, data } = useQuery(['repoData'], () =>
// fetch('https://api.github.com/repos/tannerlinsley/react-query').then(res =>
// const { isLoading, error, data } = useQuery({
// queryKey: ['repoData'], () =>
// queryFn: fetch('https://api.github.com/repos/tannerlinsley/react-query').then(res =>
// res.json()
// )
// )
// })

// ✅ solid version -- does not support destructuring outside reactive context
const query = createQuery(
() => ['repoData'],
() =>
const query = createQuery({
queryKey: () => ['repoData'],
queryFn: () =>
fetch('https://api.github.com/repos/tannerlinsley/react-query').then(
(res) => res.json(),
),
)
})

// ✅ access query properties in JSX reactive context
return (
Expand Down Expand Up @@ -162,7 +176,9 @@ const queryClient = new QueryClient()

function Example() {
const [enabled, setEnabled] = createSignal(false)
const query = createQuery(() => ['todos'], fetchTodos, {
const query = createQuery({
queryKey: () => ['todos'],
queryFn: fetchTodos,
// ❌ passing a signal directly is not reactive
// enabled: enabled(),

Expand Down
14 changes: 6 additions & 8 deletions examples/react/load-more-infinite-scroll/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ function Example() {
fetchPreviousPage,
hasNextPage,
hasPreviousPage,
} = useInfiniteQuery(
['projects'],
async ({ pageParam = 0 }) => {
} = useInfiniteQuery({
queryKey: ['projects'],
queryFn: async ({ pageParam = 0 }) => {
const res = await axios.get('/api/projects?cursor=' + pageParam)
return res.data
},
{
getPreviousPageParam: (firstPage) => firstPage.previousId ?? undefined,
getNextPageParam: (lastPage) => lastPage.nextId ?? undefined,
},
)
getPreviousPageParam: (firstPage) => firstPage.previousId ?? undefined,
getNextPageParam: (lastPage) => lastPage.nextId ?? undefined,
})

React.useEffect(() => {
if (inView) {
Expand Down
10 changes: 5 additions & 5 deletions examples/react/react-native/src/screens/MovieDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ type Props = {
};

export function MovieDetailsScreen({ route }: Props) {
const { isLoading, error, data, refetch } = useQuery<MovieDetails, Error>(
['movie', route.params.movie.title],
() => fetchMovie(route.params.movie.title),
{ initialData: route.params.movie as MovieDetails }
);
const { isLoading, error, data, refetch } = useQuery<MovieDetails, Error>({
queryKey: ['movie', route.params.movie.title],
queryFn: () => fetchMovie(route.params.movie.title),
initialData: route.params.movie as MovieDetails,
});

const { isRefetchingByUser, refetchByUser } = useRefreshByUser(refetch);

Expand Down
8 changes: 4 additions & 4 deletions examples/react/react-native/src/screens/MoviesListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ type Props = {
};

export function MoviesListScreen({ navigation }: Props) {
const { isLoading, error, data, refetch } = useQuery<Movie[], Error>(
['movies'],
fetchMovies
);
const { isLoading, error, data, refetch } = useQuery<Movie[], Error>({
queryKey: ['movies'],
queryFn: fetchMovies,
});
const { isRefetchingByUser, refetchByUser } = useRefreshByUser(refetch);
useRefreshOnFocus(refetch);

Expand Down
2 changes: 1 addition & 1 deletion examples/react/react-router/src/routes/root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const action = (queryClient) => async () => {
export default function Root() {
const { q } = useLoaderData();
const { data: contacts } = useQuery(contactListQuery(q));
const searching = useIsFetching(["contacts", "list"]) > 0;
const searching = useIsFetching({ queryKey: ["contacts", "list"] }) > 0;
const navigation = useNavigation();
const submit = useSubmit();

Expand Down
12 changes: 5 additions & 7 deletions examples/solid/basic-typescript/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ const getPostById = async (id: number): Promise<Post> => {
}

function createPost(postId: number) {
return createQuery(
() => ['post', postId],
() => getPostById(postId),
{
enabled: !!postId,
},
)
return createQuery({
queryKey: () => ['post', postId],
queryFn: () => getPostById(postId),
enabled: !!postId,
})
}

function Post(props: { postId: number; setPostId: Setter<number> }) {
Expand Down
Loading