Skip to content

Instantly share code, notes, and snippets.

@manuel-mauky
Created June 15, 2020 18:16
Show Gist options
  • Save manuel-mauky/5ada30dbe6b151761f76f6948c8e23c5 to your computer and use it in GitHub Desktop.
Save manuel-mauky/5ada30dbe6b151761f76f6948c8e23c5 to your computer and use it in GitHub Desktop.
React-Hooks-Article: Load data Function component with cleanup
useEffect(() => {
const controller = new AbortController()
fetch("/some-data.json", { signal: controller.signal })
.then((response) => response.json())
.then((data) => {
setData(data)
})
return () => {
controller.abort()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment