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
export const preventOrphanWord = (string) => { | |
const words = string.trim().split(' '); | |
// Only proceed if we've got at least 3 words | |
if (words.length < 3) { | |
return string; | |
} | |
const [nextToLastWord, lastWord] = words.slice(-2); | |
const precedingWords = words.slice(0, words.length - 2); |
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, { useContext, useEffect, useRef } from 'react'; | |
import PropTypes from 'prop-types'; | |
import TabContext from './TabContext'; | |
import getAttributeProps from './getAttributeProps'; | |
const propTypes = { | |
children: PropTypes.oneOfType([ | |
PropTypes.arrayOf(PropTypes.node), | |
PropTypes.node | |
]).isRequired, |
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 * 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
import debounce from "lodash/debounce"; | |
const getPageHeight = () => | |
Math.max( | |
document.body.scrollHeight, | |
document.body.offsetHeight, | |
document.documentElement.clientHeight, | |
document.documentElement.scrollHeight, | |
document.documentElement.offsetHeight | |
); |
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
let bodyBlocked = false; | |
const { body, documentElement: html } = document; | |
export const blockScroll = () => { | |
if (bodyBlocked) { | |
return; | |
} | |
const scrollBarWidth = window.innerWidth - html.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
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, useRef } from 'react'; | |
/** | |
* Usage: | |
* const [count, setCount] = useState(0); | |
* const prevCount = usePrevious(count); | |
*/ | |
export default value => { | |
const ref = useRef(); | |
NewerOlder