package.react-utils.useMutationWithInvalidation.useMutationWithInvalidation.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neeto-commons-frontend Show documentation
Show all versions of neeto-commons-frontend Show documentation
A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.
{"version":3,"file":"useMutationWithInvalidation.js","names":["useQueryClient","useMutation","type","useMutationWithInvalidation","mutationFn","_ref","keysToInvalidate","options","_objectWithoutProperties","_excluded","queryClient","onSuccess","otherOptions","_excluded2","_objectSpread","data","variables","context","forEach","key","result","invalidateQueries","queryKey"],"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,SAASA,cAAc,EAAEC,WAAW,QAAQ,uBAAuB;AACnE,SAASC,IAAI,QAAQ,OAAO;AAE5B,IAAMC,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAC/BC,UAAU,EAAAC,IAAA,EAEP;EAAA,IADDC,gBAAgB,GAAAD,IAAA,CAAhBC,gBAAgB;IAAKC,OAAO,GAAAC,wBAAA,CAAAH,IAAA,EAAAI,SAAA;EAE9B,IAAMC,WAAW,GAAGV,cAAc,CAAC,CAAC;EACpC,IAAQW,UAAS,GAA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