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
const fetchGraphQL = async ({ url, query, variables, headers }) => { | |
const response = await fetch(url, { | |
method: "POST", | |
headers: { | |
...headers, | |
"Content-Type": "application/json" | |
}, | |
body: JSON.stringify({ query, variables }) | |
}); |
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
export default { | |
FEATURE_A: { | |
name: 'FEATURE_A', | |
description: 'Human readable description of feature A', | |
enabled: { | |
development: true, | |
production: false | |
} | |
}, | |
FEATURE_B: { |
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 * as React from 'react'; | |
interface Props extends React.HTMLProps<HTMLInputElement> { | |
onFileSelect: (file: File) => void; | |
} | |
const FileInput = ({ onFileSelect, ...props }: Props) => { | |
const inputRef = React.useRef<HTMLInputElement>(); | |
const onChange = (event: React.ChangeEvent) => { |
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
Show hidden characters
{ | |
"presets": [ | |
[ | |
"@babel/preset-env", | |
{ | |
"useBuiltIns": "usage" | |
} | |
], | |
"@babel/preset-react" | |
], |
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 { useEffect, useRef } from 'react' | |
const isFunction = fn => typeof fn === 'function'; | |
const connectionIsOpen = ws => ws && ws.readyState === WebSocket.OPEN; | |
/** | |
* Usage: | |
* const { webSocket, sendMessage, closeConnection } = useWebSocket({ | |
* url: 'wss://echo.websocket.org/', | |
* onOpen: useCallback(event => { |
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 { useEffect, useState } from "react"; | |
const useProximity = (elemRef, perimeter = 100) => { | |
const [withinPerimeter, setWithinPerimeter] = useState(false); | |
useEffect(() => { | |
if (!elemRef || !elemRef.current) return; | |
let ticking = false; | |
const { current } = elemRef; |
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
const SCROLL_UP = "up"; | |
const SCROLL_DOWN = "down"; | |
const useScrollDirection = ({ | |
initialDirection, | |
thresholdPixels, | |
off | |
} = {}) => { | |
const [scrollDir, setScrollDir] = useState(initialDirection); |
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 { useRef } from 'react'; | |
const safeDocument = typeof document !== 'undefined' ? document : {}; | |
/** | |
* Usage: | |
* const [blockScroll, allowScroll] = useScrollBlock(); | |
*/ | |
export default () => { | |
const scrollBlocked = useRef(); |
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 { useEffect } from 'react'; | |
/** | |
* Usage: | |
* useClickOutside(myRef, event => { | |
* console.log(`${event.target} is outside of ${myRef.current}`); | |
* }); | |
*/ | |
export default (elemRef, fn) => { | |
useEffect(() => { |
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 { useEffect, useRef } from 'react'; | |
/** | |
* Usage: | |
* const [count, setCount] = useState(0); | |
* const prevCount = usePrevious(count); | |
*/ | |
export default value => { | |
const ref = useRef(); | |
NewerOlder