Skip to content

Instantly share code, notes, and snippets.

@hesan-aminiloo
Created July 15, 2022 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hesan-aminiloo/cf4988045c4d53c4ab96049e332cba79 to your computer and use it in GitHub Desktop.
Save hesan-aminiloo/cf4988045c4d53c4ab96049e332cba79 to your computer and use it in GitHub Desktop.
const useFetch = (path, method) => {
const [data, setData] = useState(null);
useEffect(() => {
fetch(path, { method: method.toUpperCase() })
.then((response) => response.json())
.then((json) => setData(json));
}, []);
return data;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment