Created
August 4, 2019 23:59
-
-
Save Keldrik/cd775a9dacd43e25c14bf62e0f0347c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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