-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: replace effects with react query callbacks
- Loading branch information
1 parent
80c3415
commit 534c403
Showing
13 changed files
with
195 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
import { QueryClient } from '@gobob/react-query'; | ||
import { QueryCache, QueryClient } from '@gobob/react-query'; | ||
|
||
const queryClient = new QueryClient(); | ||
const queryClient = new QueryClient({ | ||
queryCache: new QueryCache({ | ||
onError: (error, query) => { | ||
if (typeof query.meta?.onError === 'function') query.meta.onError(error, query); | ||
}, | ||
onSuccess(data, query) { | ||
if (typeof query.meta?.onSuccess === 'function') query.meta.onSuccess(data, query); | ||
}, | ||
onSettled(data, error, query) { | ||
if (typeof query.meta?.onSettled === 'function') query.meta.onSettled(data, error, query); | ||
} | ||
}) | ||
}); | ||
|
||
export { queryClient }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import '@gobob/react-query'; | ||
import { DefaultError, Query } from '@gobob/react-query'; | ||
|
||
// https://tanstack.com/query/latest/docs/framework/react/typescript#typing-meta | ||
interface CustomQueryMeta<TQueryFnData = unknown> extends Record<string, unknown> { | ||
onSuccess?: ((data: TQueryFnData, query: Query<TQueryFnData, unknown, unknown>) => void) | undefined; | ||
onError?: ((error: DefaultError, query: Query<TQueryFnData, unknown, unknown>) => void) | undefined; | ||
onSettled?: | ||
| (( | ||
data: TQueryFnData | undefined, | ||
error: DefaultError | null, | ||
query: Query<TQueryFnData, unknown, unknown> | ||
) => void) | ||
| undefined; | ||
} | ||
|
||
declare module '@gobob/react-query' { | ||
interface Register extends Record<string, unknown> { | ||
queryMeta: CustomQueryMeta; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import { QueryClient } from '@gobob/react-query'; | ||
import { QueryCache, QueryClient } from '@gobob/react-query'; | ||
|
||
const queryClient = new QueryClient(); | ||
const queryClient = new QueryClient({ | ||
queryCache: new QueryCache({ | ||
onError: (error, query) => { | ||
if (typeof query.meta?.onError === 'function') query.meta.onError(error, query); | ||
}, | ||
onSuccess(data, query) { | ||
if (typeof query.meta?.onSuccess === 'function') query.meta.onSuccess(data, query); | ||
}, | ||
onSettled(data, error, query) { | ||
if (typeof query.meta?.onSettled === 'function') query.meta.onSettled(data, error, query); | ||
} | ||
}) | ||
}); | ||
|
||
export { queryClient }; | ||
export * from './keys'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import '@gobob/react-query'; | ||
import { DefaultError, Query } from '@gobob/react-query'; | ||
|
||
// https://tanstack.com/query/latest/docs/framework/react/typescript#typing-meta | ||
interface CustomQueryMeta<TQueryFnData = unknown> extends Record<string, unknown> { | ||
onSuccess?: ((data: TQueryFnData, query: Query<TQueryFnData, unknown, unknown>) => void) | undefined; | ||
onError?: ((error: DefaultError, query: Query<TQueryFnData, unknown, unknown>) => void) | undefined; | ||
onSettled?: | ||
| (( | ||
data: TQueryFnData | undefined, | ||
error: DefaultError | null, | ||
query: Query<TQueryFnData, unknown, unknown> | ||
) => void) | ||
| undefined; | ||
} | ||
|
||
declare module '@gobob/react-query' { | ||
interface Register extends Record<string, unknown> { | ||
queryMeta: CustomQueryMeta; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import '@tanstack/react-query'; | ||
import { DefaultError, Query } from '@tanstack/react-query'; | ||
|
||
// https://tanstack.com/query/latest/docs/framework/react/typescript#typing-meta | ||
interface CustomQueryMeta<TQueryFnData = unknown> extends Record<string, unknown> { | ||
onSuccess?: ((data: TQueryFnData, query: Query<TQueryFnData, unknown, unknown>) => void) | undefined; | ||
onError?: ((error: DefaultError, query: Query<TQueryFnData, unknown, unknown>) => void) | undefined; | ||
onSettled?: | ||
| (( | ||
data: TQueryFnData | undefined, | ||
error: DefaultError | null, | ||
query: Query<TQueryFnData, unknown, unknown> | ||
) => void) | ||
| undefined; | ||
} | ||
|
||
declare module '@tanstack/react-query' { | ||
interface Register extends Record<string, unknown> { | ||
queryMeta: CustomQueryMeta; | ||
} | ||
} |
Oops, something went wrong.