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 { noop } from '../utils'; | |
| function copy(text) { | |
| if (navigator.clipboard) { | |
| return navigator.clipboard.writeText(text).catch((error) => { | |
| throw error !== undefined | |
| ? error | |
| : new DOMException('The request is not allowed', 'NotAllowedError'); | |
| }); | |
| } |
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, useCallback, useRef } from 'react'; | |
| export default function useDebounce(callback, wait) { | |
| const timer = useRef(); | |
| const cancel = useCallback(() => { | |
| if (timer.current) { | |
| clearTimeout(timer.current); | |
| } |
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, useCallback, useRef } from 'react'; | |
| export default function useThrottle(callback, wait, { immediate = false } = {}) { | |
| const timer = useRef(); | |
| const inThrottle = useRef(false); | |
| const cancel = useCallback(() => { | |
| if (timer.current) { | |
| clearTimeout(timer.current); | |
| } |
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'; | |
| export default function usePreviousValue(value) { | |
| const ref = useRef(); | |
| useEffect(() => { | |
| ref.current = value; | |
| }, [value]); | |
| return ref.current; |
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, useRef, useEffect, | |
| } from 'react'; | |
| import { useRouter } from 'next/router'; | |
| import { useEventCallback } from '@material-ui/core/utils'; | |
| export default function usePageRefresh(callback, { skip } = {}) { | |
| const router = useRouter(); | |
| const [refreshing, setRefreshing] = useState(false); | |
| const currentAsPath = 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 { useState } from 'react'; | |
| export default function useLocalStorage(key, initialValue) { | |
| const [storedValue, setStoredValue] = useState(() => { | |
| try { | |
| const item = window.localStorage.getItem(key); | |
| return item ? JSON.parse(item) : initialValue; | |
| } catch (error) { | |
| return initialValue; | |
| } |
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, useCallback, useEffect } from 'react'; | |
| import useEventListener from './use-event-listener'; | |
| const keyCodeAliasMapping = { | |
| esc: 27, | |
| tab: 9, | |
| enter: 13, | |
| space: 32, | |
| up: 38, | |
| left: 37, |
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 { useRouter } from 'next/router'; | |
| import { openMiniProgramSchema } from '@/modules/utils'; | |
| let basePage = {}; | |
| export default function useFullscreenLayout() { | |
| const router = useRouter(); | |
| const handleRouteChange = (url) => { | |
| if (url === basePage.asPath) { |
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'; | |
| function getElement(element) { | |
| return typeof element === 'function' ? element() : element; | |
| } | |
| export default function useEventListener( | |
| element, eventName, handler, { skip = false, ...options } = {}, | |
| ) { | |
| const handlerRef = useRef(); |
NewerOlder