Skip to content

Instantly share code, notes, and snippets.

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