All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.cjs.react-utils.useMutationWithInvalidation.useMutationWithInvalidation.js.map Maven / Gradle / Ivy

Go to download

A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.

There is a newer version: 4.12.3
Show newest version
{"version":3,"file":"useMutationWithInvalidation.js","names":["_reactQuery","require","_ramda","_excluded","_excluded2","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","useMutationWithInvalidation","mutationFn","_ref","keysToInvalidate","options","_objectWithoutProperties2","queryClient","useQueryClient","onSuccess","otherOptions","useMutation","data","variables","context","result","type","invalidateQueries","queryKey","_default","exports"],"sources":["../../../../src/react-utils/useMutationWithInvalidation/useMutationWithInvalidation.js"],"sourcesContent":["import { useQueryClient, useMutation } from \"@tanstack/react-query\";\nimport { type } from \"ramda\";\n\nconst useMutationWithInvalidation = (\n  mutationFn,\n  { keysToInvalidate, ...options }\n) => {\n  const queryClient = useQueryClient();\n  const { onSuccess, ...otherOptions } = options;\n\n  return useMutation({\n    mutationFn,\n    onSuccess: (data, variables, context) => {\n      keysToInvalidate.forEach(key => {\n        const result =\n          type(key) === \"Function\" ? key(data, variables, context) : key;\n\n        if (type(result) === \"Object\") {\n          queryClient.invalidateQueries(result);\n        } else if (type(result) === \"String\") {\n          queryClient.invalidateQueries({ queryKey: [result] });\n        } else {\n          queryClient.invalidateQueries({ queryKey: result });\n        }\n      });\n\n      onSuccess?.(data, variables, context);\n    },\n\n    ...otherOptions,\n  });\n};\n\nexport default useMutationWithInvalidation;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAA6B,IAAAE,SAAA;EAAAC,UAAA;AAAA,SAAAC,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAA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