Created
May 15, 2023 07:59
-
-
Save adrian-afergon/3185e73109176cb595744ca356711b3e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import {useSWRConfig} from "swr"; | |
interface UseDataMutation<T> { | |
key: string, | |
mutation: (data: T) => Promise<T> | |
} | |
export const useDataMutation = <T>({key, mutation}: UseDataMutation<T> ) => { | |
const { mutate: swrMutate } = useSWRConfig() | |
const mutate = async (data: T) => { | |
await swrMutate(key, mutation(data)) | |
} | |
return {mutate} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment