Skip to content

Commit

Permalink
Don't use type casting
Browse files Browse the repository at this point in the history
  • Loading branch information
dilirity committed Feb 4, 2025
1 parent 88d1c8f commit 16156da
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions projects/js-packages/react-data-sync-client/src/DataSyncHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,13 @@ export function useDataSync<
// AbortController is used to track rapid value mutations
// and will cancel in-flight requests and prevent
// the optimistic value from being reverted.
const getAbortController = () =>
queryClient.getMutationDefaults( queryKey )?.meta?.abortController as AbortController;
const getAbortController = () => {
const defaults = queryClient.getMutationDefaults( queryKey );
return defaults?.meta?.abortController instanceof AbortController
? defaults.meta.abortController
: undefined;
};

const setAbortController = ( abortController: AbortController ) => {
queryClient.setMutationDefaults( queryKey, {
meta: {
Expand All @@ -146,7 +151,7 @@ export function useDataSync<
*/
const mutationConfigDefaults = {
meta: {
abortController: null as AbortController | null,
abortController: null,
},
// Mutation function that's called when the mutation is triggered
mutationFn: value => datasync.SET( value, params, getAbortController()?.signal ),
Expand Down

0 comments on commit 16156da

Please sign in to comment.