Created
May 15, 2023 07:58
-
-
Save adrian-afergon/aa1d246b2545df70b2e8b6921b527eef to your computer and use it in GitHub Desktop.
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
import useSWR from "swr" | |
interface UseData<T> { | |
key: string, | |
fetcher: () => Promise<T> | |
} | |
interface Response <T> { | |
data: T | undefined | |
error: string | undefined | |
loading: boolean | |
} | |
export const useData = <T>({key, fetcher} :UseData<T>): Response<T> => { | |
const {data, error, isValidating} = useSWR<T, string>(key, fetcher) | |
return {data, error, loading: isValidating} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment