Last active
July 22, 2020 14:25
-
-
Save raulpesilva/768aa730b794635a0445d8f105ef9527 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 useSWR from 'swr'; | |
export function useFetch(url) { | |
const { data, error } = useSWR(url, async (url) => { | |
const response = await fetch(url); | |
const dataString = await response.json(); | |
const { data } = await JSON.parse(dataString); | |
return data; | |
}); | |
return { data, error }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment