Skip to content

Instantly share code, notes, and snippets.

@simicd
Created September 27, 2020 17:27
Show Gist options
  • Save simicd/3cdbce31f793692ef3ca4720f8121284 to your computer and use it in GitHub Desktop.
Save simicd/3cdbce31f793692ef3ca4720f8121284 to your computer and use it in GitHub Desktop.
import { useState, useEffect, useCallback } from "react";
// ...
export const useFetch = <T>({ url, init, processData }: RequestProps<T>) => {
// ...
// Define asynchronous function
const fetchApi = async () => {
// ...
};
useEffect(() => {
// Call async function
fetchApi();
// ...
}, [stringifiedUrl, stringifiedInit, processJson]);
return { data, fetchApi };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment