Skip to content

Instantly share code, notes, and snippets.

@Keldrik
Created August 4, 2019 23:59
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 Keldrik/cd775a9dacd43e25c14bf62e0f0347c6 to your computer and use it in GitHub Desktop.
Save Keldrik/cd775a9dacd43e25c14bf62e0f0347c6 to your computer and use it in GitHub Desktop.
import { useState, useEffect } from 'react';
const useDataFetch = url => {
const [data, setData] = useState(null);
useEffect(() => {
const loadData = async url => {
const response = await fetch(url);
const json = await response.json();
setData(json);
};
loadData(url);
}, [url]);
return data;
};
export default useDataFetch;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment