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
'use client'; | |
import createCache from '@emotion/cache'; | |
import {CacheProvider, EmotionCache} from '@emotion/react'; | |
import { | |
SerializedStyles, | |
StyleSheet | |
} from '@emotion/utils/dist/declarations/types'; | |
import {useServerInsertedHTML} from 'next/navigation'; | |
import {FC, PropsWithChildren, useCallback, useMemo} from '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, useState} from 'react'; | |
export const useBounceValue = <TValue,>( | |
newValue: TValue, | |
defaultValue: TValue, | |
delay: number | |
) => { | |
const [value, setValue] = useState<TValue>(defaultValue); | |
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
{ | |
"AED": "United Arab Emirates Dirham", | |
"AFN": "Afghan Afghani", | |
"ALL": "Albanian Lek", | |
"AMD": "Armenian Dram", | |
"ANG": "Netherlands Antillean Guilder", | |
"AOA": "Angolan Kwanza", | |
"ARS": "Argentine Peso", | |
"AUD": "Australian Dollar", | |
"AWG": "Aruban Florin", |
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 {MutableRefObject, useEffect, useState} from 'react'; | |
const toRect = (rect: DOMRect | undefined) => { | |
const width = rect?.width || 0, | |
height = rect?.height || 0, | |
x = rect?.x || 0, | |
y = rect?.y || 0; | |
return {width, height, x, y}; | |
}; |
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 {useCallback, useState} from 'react'; | |
const useToggle = (init: boolean = false): [boolean, (v: unknown) => void] => { | |
const [toggle, setToggle] = useState(init); | |
const callback = useCallback((value) => { | |
setToggle((prev) => (typeof value === 'boolean' ? value : !prev)); | |
}, []); | |
return [toggle, callback]; | |
}; |
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'; | |
export function usePrevious(value) { | |
const ref = useRef(value); | |
useEffect(() => { | |
ref.current = value; | |
}, [value]); | |
return ref.current; |
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 useGotQuote = () => { | |
const [quote, setQuote] = useState(''); | |
useEffect(() => { | |
fetch('https://game-of-thrones-quotes.herokuapp.com/v1/random') | |
.then((response) => response.json()) | |
.then((data) => setQuote(data?.sentence)); | |
}, []); | |
return quote; |
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 {useMemo } from 'react'; | |
const CODE: Record<string, string> = { | |
IN: 'INR', | |
SE: 'SEK', | |
GB: 'GBP', | |
IE: 'EUR', | |
CN: 'CNY', | |
JP: 'JPY', | |
US: 'USD', |
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 useGeoLocation = (options?: PositionOptions) => { | |
const [geo, setGeo] = useState<GeolocationPosition>(); | |
const [err, setError] = useState<GeolocationPositionError>(); | |
useEffect(() => { | |
const id = navigator.geolocation.watchPosition( | |
(pos) => { | |
setGeo(pos); | |
err && setError(undefined); |
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, useMemo} from 'react'; | |
export const useAudio = ( | |
src: string, | |
play: boolean, | |
volume: number, | |
loop: boolean, | |
onDone?: () => void | |
) => { | |
const audio = useMemo(() => { |
NewerOlder