Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fadi-george/32a6c8312d04aa17be98de6d1b7257cc to your computer and use it in GitHub Desktop.
Save fadi-george/32a6c8312d04aa17be98de6d1b7257cc to your computer and use it in GitHub Desktop.
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;
};
@fadi-george
Copy link
Author

fadi-george commented Mar 23, 2022

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