Created
July 1, 2020 06:22
-
-
Save fadi-george/32a6c8312d04aa17be98de6d1b7257cc 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
interface SWRProps { | |
api: keyInterface; | |
children?: Function | null; | |
options?: any; | |
showRetry?: boolean; | |
} | |
export const Fetcher: React.FC<SWRProps> = ({ | |
api, | |
children, | |
options, | |
showRetry = true, | |
}) => { | |
const { data, error, mutate } = useSWR(api, options); | |
if (api !== null && !data) return <Spinner />; | |
if (error) | |
return ( | |
<ErrorView | |
onRetry={() => mutate(api)} | |
showRetry={showRetry} | |
title={error!.message} | |
/> | |
); | |
return children ? (children as Function)(data) : null; | |
}; |
const useUser = (userID: number) => useSWR('/api/user/${userID}', { revalidateOnMount: false })
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
E.g.