Skip to content

Instantly share code, notes, and snippets.

@simicd
Created August 16, 2020 18:22
Show Gist options
  • Save simicd/3fa8d95a74a5ee12e852383d384da50d to your computer and use it in GitHub Desktop.
Save simicd/3fa8d95a74a5ee12e852383d384da50d to your computer and use it in GitHub Desktop.
// useFetch.ts
// ...
export const useFetch = ({ url, init }: RequestProps) => {
// Response state
const [data, setData] = useState<DogImageType>();
useEffect(() => {
// Define asynchronous function
const fetchApi = async () => {
// ...
};
// Call async function
fetchApi();
}, []);
return data;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment