Skip to content

Instantly share code, notes, and snippets.

View DennyScott's full-sized avatar

Denny Scott DennyScott

  • Winnipeg, Manitoba
View GitHub Profile
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) {
fetch(proxyUrl + targetUrl)
.then(response => response.json())
.then(facts => {
export function CatFacts() {
const [data, setData] = useState(null);
const proxyUrl = "https://cors-anywhere.herokuapp.com/";
const targetUrl = `https://cat-fact.herokuapp.com/facts/random`;
if(!data) {
fetch(proxyUrl + targetUrl)
.then(response => response.json())
.then(facts => {
setData(facts.text);
export function CatFacts() {
const [data, setData] = useState(null);
const proxyUrl = "https://cors-anywhere.herokuapp.com/";
const targetUrl = `https://cat-fact.herokuapp.com/facts/random`;
fetch(proxyUrl + targetUrl)
.then(response => response.json())
.then(facts => {
setData(facts.text);
});
return <div>{data}</div>;
export function CatFacts() {
const proxyUrl = "https://cors-anywhere.herokuapp.com/";
const targetUrl = `https://cat-fact.herokuapp.com/facts/random`;
let data;
function getData() {
fetch(proxyUrl + targetUrl)
.then(response => response.json())
.then(facts => data = facts);
}
useEffect(() => someCode())
function MyComponent({username}) {
const [isOpen, setOpen] = useState(false);
return (...)
}
function MyComponent({username}) {
const [user, setUser] = useState(username);
return (...)
}
function ComponentUsingHOC({ user, color, location }) {
return (
<div>
<div>Color : {color}</div>
User: {user.name}
<Location
city={location.city}
country={location.country}
/>
</div>
function ComponentWithHook() {
const user = useSelector(state => state.user);
const color = useSelector(state => state.color);
const location = useSelector(state => state.user.location);
return (
<div>
<div>Color : {color}</div>
User: {user.name}
<Location city={location.city} country={location.country} />
const newSelectedState = latestSelector.current(store.getState())
if (equalityFn(newSelectedState, latestSelectedState.current)) {
return
}
forceRender({})