Created
March 7, 2020 08:41
-
-
Save DennyScott/609f12ffa14bbae879d5dfbb75e4d9a3 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 function CatFacts({ id }) { | |
const [data, setData] = useState(); | |
useEffect(() => { | |
const proxyUrl = "https://cors-anywhere.herokuapp.com/"; | |
const targetUrl = `https://cat-fact.herokuapp.com/facts/${id}`; | |
fetch(proxyUrl + targetUrl) | |
.then(response => response.json()) | |
.then(facts => { | |
setData(facts.text); | |
}); | |
}, [id, setData]); | |
return <div>Cat Fact: {data}</div>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment