Skip to content

Instantly share code, notes, and snippets.

View DennyScott's full-sized avatar

Denny Scott DennyScott

  • Winnipeg, Manitoba
View GitHub Profile
function ValueEq() {
const A = 'hello';
const B = 'goodbye';
const C = 'hello';
}
// A === 'hello'
// B === 'goodbye'
// C === 'hello'
function ExampleComponent({url}) {
useEffect(() => {
const fetchData = (url) => {
// fetch call here
}
fetchData(url)
}, [url]);
return (<div></div>);
}
function ExampleComponent({url}) {
const fetchData = (url) => {
// fetch call here
}
useEffect(() => fetchData(url), [url, fetchData]);
return (<div></div>);
}
function ExampleComponent({url}) {
useEffect(() => fetchData(url), [url]);
return (<div></div>);
}
function ExampleComponent({url}) {
useEffect(() => fetchData(url), []);
return (<div></div>);
}
function ExampleComponent({id}) {
useEffect(() => doSomething(id), [id]);
return (<div></div>);
}
function ExampleComponent({id}) {
useEffect(() => doSomething(id));
return (<div></div>);
}
export function CatFacts({ id }) {
const data = useFetchCatFact(id);
return <div>Cat Fact: {data}</div>;
}
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);
});
export function CatFacts({ id }) {
const [data, setData] = useState();
const [urlOfData, setUrlOfData] = useState();
const proxyUrl = "https://cors-anywhere.herokuapp.com/";
const targetUrl = `https://cat-fact.herokuapp.com/facts/${id}`;
if (!data || urlOfData !== id) {
setTimeout(() => {
fetch(proxyUrl + targetUrl)
.then(response => response.json())