This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deepEquals(a, b) { | |
if(a === b) { | |
return true; | |
} | |
if(a && b && typeof a === 'object' && typeof b === 'object' && Object.keys(a).length === Object.keys(b).length && Array.isArray(a) === Array.isArray(b)) { | |
for(let key in a) { | |
if(key in b) { | |
if(!deepEquals(a[key], b[key]) { | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pass an ElementType and get boolean | |
export const isInViewport = el => { | |
const rect = el.getBoundingClientRect(); | |
return ( | |
rect.right >= 0 && | |
rect.bottom >= 0 && | |
rect.top <= (window.innerHeight || document.documentElement.clientHeight) && | |
rect.left <= (window.innerWidth || document.documentElement.clientWidth) | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Component() { | |
const [count, setCount] = useState(0); | |
const prevCount = useRef(null); | |
useEffect(() => { | |
// only for the first render, where 'decreased' would have been shown. | |
if(prevCount.current === null) { | |
prevCount.current = count; | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useReducer } from 'react'; | |
function Component() { | |
const [ignored, forceUpdate] = useReducer(x => x + 1, 0); | |
function handleClick() { | |
forceUpdate(); | |
} | |
return ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect, useRef } from 'react'; | |
function Abc() { | |
const [abc, setAbc] = useState(1); | |
const isFirstRun = useRef(true); | |
useEffect (() => { | |
if (isFirstRun.current) { | |
isFirstRun.current = false; | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This optional code is used to register a service worker. | |
// register() is not called by default. | |
// This lets the app load faster on subsequent visits in production, and gives | |
// it offline capabilities. However, it also means that developers (and users) | |
// will only see deployed updates on subsequent visits to a page, after all the | |
// existing tabs open on the page have been closed, since previously cached | |
// resources are updated in the background. | |
// To learn more about the benefits of this model and instructions on how to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createStore(reducer) { | |
var state; | |
var listeners = [] | |
function getState() { | |
return state | |
} | |
function subscribe(listener) { | |
listeners.push(listener) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import app from './app.js' | |
const polyfills = [] | |
if (!window.fetch) { | |
polyfills.push(import(/* webpackChunkName: "polyfill-fetch" */ 'whatwg-fetch')) | |
} | |
Promise.all(polyfills) | |
.then(app) | |
.catch((error) => { | |
console.error('Failed fetching polyfills', error) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import React, { PureComponent } from 'react'; | |
import GalleryBoxWithIntersection from './GalleryBoxWithIntersection'; | |
import GalleryBoxWithoutIntersection from './GalleryBoxWithoutIntersection'; | |
type Image = { | |
url: string, | |
height: number, | |
width: number, |