Skip to content

Instantly share code, notes, and snippets.

@simicd
Last active August 17, 2020 19:26
Show Gist options
  • Save simicd/0154eea4334ccaba00802fd4d780ab3e to your computer and use it in GitHub Desktop.
Save simicd/0154eea4334ccaba00802fd4d780ab3e 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
// ...
}, [url, init]); // Add dependency list
return data;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment