Skip to content

Instantly share code, notes, and snippets.

@evasconcelos
Created March 30, 2021 07:26
Show Gist options
  • Save evasconcelos/f0b47a5e4a9f619379806172627fd166 to your computer and use it in GitHub Desktop.
Save evasconcelos/f0b47a5e4a9f619379806172627fd166 to your computer and use it in GitHub Desktop.
Dependency inversion principle: Breaking it
import { useEffect, useState } from "react";
import axios from "axios";
export default function App() {
const [fact, setFact] = useState("");
useEffect(() => {
axios.get("https://cat-fact-herokuapp.com/facts").then((res) => {
setFact(res.data[0].text);
});
}, []);
return (
<div className="App">
<h1>Cat Facts</h1>
<p>{fact}</p>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment