Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

bug-reports.output.tsx

63 lines1.7 KB

1// From: https://github.com/TanStack/query/issues/6204
2export function useDetails({ groupId }: { groupId?: string }): any {
3 const cacheKey = ["details", groupId];
4 const query = () => fetch(`/group/${groupId}`);
5 const queryObject = useQuery({
6 queryKey: cacheKey,
7 queryFn: query,
8 enabled: !!groupId
9 });
10 return queryObject;
12​
13// Based on: https://github.com/TanStack/query/issues/6204
14export function useDetailsContainsIdentifierAsThirdArgument({ groupId }: { groupId?: string }): any {
15 const cacheKey = ["details", groupId];
16 const query = () => fetch(`/group/${groupId}`);
17 const opts = { enabled: !!groupId }
18 const queryObject = useQuery({
19 queryKey: cacheKey,
20 queryFn: query,
21 ...opts
22 });
23 return queryObject;
25​
26// From: https://twitter.com/samcook_/status/1715063150184132902
27export function useWhatever({ thing }: { thing: string }) {
28 return useQuery({
29 queryKey: ['some-string', someVar],
30 queryFn: async () => 'foo',
31 enabled: Boolean(thing)
32 });
34​
35// From: https://github.com/TanStack/query/issues/6548
36export function useDeleteSomething(): any {
37 return useMutation({
38 mutationFn: ({ groupId }: { groupId: string }) => {
39 return fetch(`/api/groups/${groupId}`, {
40 method: 'DELETE',
41 });
42 }
43 });
45​
46// From: https://github.com/TanStack/query/issues/6548
47export function useDeleteSomethingWithOnError(): any {
48 return useMutation({
49 mutationFn: ({ groupId }: { groupId: string }) => {
50 return fetch(`/api/groups/${groupId}`, {
51 method: 'DELETE',
52 });
53 },
54​
55 onError: (_error, _variables, context) => {
56 // An error happened!
57 console.log(
58 `rolling back optimistic delete with id ${context.id}`
59 );
60 }
61 });
63​