Skip to content

Instantly share code, notes, and snippets.

@DennyScott
Created March 7, 2020 08:48
Show Gist options
  • Save DennyScott/75e420d8221531662645244b3b6a6c6a to your computer and use it in GitHub Desktop.
Save DennyScott/75e420d8221531662645244b3b6a6c6a to your computer and use it in GitHub Desktop.
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