This file contains hidden or 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 hidden or 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
<details class="c-menu" data-js-menu> | |
<summary id="menu-control" class="c-menu__control" data-js-menu-control> | |
Actions | |
</summary> | |
<ul id="menu" class="c-menu__list" data-js-menu-list> | |
<li> | |
<a href="#dowload">Download</a> | |
</li> | |
<li> | |
<a href="#copy">Copy to Clipboard</a> |
This file contains hidden or 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 { useState, useEffect } from 'react'; | |
/** | |
* navigator.onLine behaves a little differently across browsers | |
* (https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine#Specification). | |
* For bullet-proof detection you can add to this hook using some of the suggestions | |
* mentioned here https://www.html5rocks.com/en/mobile/workingoffthegrid/. | |
* | |
* Usage: | |
* const isOnline = useNetworkConnectivity(); |
This file contains hidden or 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(); | |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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" | |
], |