Last active
April 21, 2021 07:31
-
-
Save prdxs/4d884ea7b5a461969c4a8c1507a1d76f 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
export default function useData(initData) { | |
const [data, setData] = useState(initData); | |
useEffect(() => { | |
const intervalId = setInterval(async () => { | |
const newData = await fetch('https://data-api.com/getData').then(response => response.json()); | |
setData(newData); | |
}, 50000); | |
return () => { | |
clearInterval(intervalId); | |
}; | |
}, []); | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment