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
/** | |
* Get an element from an array | |
* @example | |
* interface Item { | |
* id: number | |
* } | |
* | |
* interface BunchOfItems extends Array<Item> {} | |
* | |
* interface SingleItemAgain extends ArrayElement<BunchOfItems> {} |
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
/* eslint-disable jest/valid-title */ | |
import React from 'react'; | |
import { render, RenderResult, waitFor } from '@testing-library/react'; | |
import chalk from 'chalk'; | |
import globby from 'globby'; | |
import path from 'path'; | |
import { | |
IncludeExcludeOptions, | |
isExportStory, | |
storyNameFromExport, |
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
/* eslint-disable react-hooks/exhaustive-deps */ | |
import * as React from 'react' | |
import { observe, unobserve } from './intersection' | |
import { InViewHookResponse, IntersectionOptions } from './index' | |
type State = { | |
inView: boolean | |
entry?: IntersectionObserverEntry | |
} |
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, {useCallback, useRef} from 'react' | |
function useHookWithRefCallback() { | |
const ref = useRef(null) | |
const setRef = useCallback(node => { | |
if (ref.current) { | |
// Make sure to cleanup any events/references added to the last instance | |
} | |
if (node) { |
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
module.exports = { | |
projects: [ | |
{ | |
displayName: 'dom', | |
testEnvironment: 'jsdom', | |
snapshotSerializers: ['enzyme-to-json/serializer'], | |
testMatch: ['**/__tests__/**/*.test.js?(x)'] | |
}, | |
{ | |
displayName: 'node', |
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 from 'react' | |
import { storiesOf } from '@storybook/react' | |
import FetchStory from './FetchStory' | |
storiesOf('Fetch Example', module) | |
.add('Plain', () => ( | |
<FetchStory mocks={{ | |
matcher: '/api/signup', | |
response: { | |
body: { |
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 loadImage(file) { | |
img = new Image(); | |
img.onload = e => drawImageToCanvas(); | |
img.onerror = e => $log.warn('Failed to load image.'); | |
fileReader = new FileReader(); | |
fileReader.onload = e => img.src = e.target.result; | |
fileReader.onerror = e => $log.warn('Failed to load file.'); | |
fileReader.readAsDataURL(file); | |
} |
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
/** | |
* @param fn {Function} Callback function to trigger on frame | |
* @param fps {int} Target FPS | |
* @returns {{pause: pause, start: start, destroy: destroy}} | |
*/ | |
function frameLoop(fn, fps=60) { | |
let then = 0; | |
let interval = 1000 / fps; | |
let isRunning = true; | |
let currentFrameId = null; |
NewerOlder