@oneplatformdev/hooks 0.1.0-8 → 0.1.0-80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +280 -0
- package/package.json +14 -19
- package/{dist/useEventListener → useEventListener}/useEventListener.d.ts +4 -2
- package/{dist/useEventListener → useEventListener}/useEventListener.d.ts.map +1 -1
- package/{dist/useHover → useHover}/useHover.d.ts +1 -1
- package/{dist/useHover → useHover}/useHover.d.ts.map +1 -1
- package/{dist/useOnClickOutside → useOnClickOutside}/useOnClickOutside.d.ts +1 -1
- package/{dist/useOnClickOutside → useOnClickOutside}/useOnClickOutside.d.ts.map +1 -1
- package/{dist/useResizeObserver → useResizeObserver}/useResizeObserver.d.ts +1 -1
- package/{dist/useResizeObserver → useResizeObserver}/useResizeObserver.d.ts.map +1 -1
- package/.babelrc +0 -12
- package/dist/CHANGELOG.md +0 -15
- package/dist/LICENSE +0 -21
- package/dist/README.md +0 -7
- package/dist/package.json +0 -68
- package/node_modules/@types/lodash.debounce/LICENSE +0 -21
- package/node_modules/@types/lodash.debounce/README.md +0 -23
- package/node_modules/@types/lodash.debounce/index.d.ts +0 -4
- package/node_modules/@types/lodash.debounce/package.json +0 -32
- package/node_modules/@types/react/LICENSE +0 -21
- package/node_modules/@types/react/README.md +0 -15
- package/node_modules/@types/react/canary.d.ts +0 -35
- package/node_modules/@types/react/compiler-runtime.d.ts +0 -4
- package/node_modules/@types/react/experimental.d.ts +0 -125
- package/node_modules/@types/react/global.d.ts +0 -160
- package/node_modules/@types/react/index.d.ts +0 -4206
- package/node_modules/@types/react/jsx-dev-runtime.d.ts +0 -45
- package/node_modules/@types/react/jsx-runtime.d.ts +0 -36
- package/node_modules/@types/react/package.json +0 -210
- package/node_modules/@types/react/ts5.0/canary.d.ts +0 -35
- package/node_modules/@types/react/ts5.0/experimental.d.ts +0 -125
- package/node_modules/@types/react/ts5.0/global.d.ts +0 -160
- package/node_modules/@types/react/ts5.0/index.d.ts +0 -4193
- package/node_modules/@types/react/ts5.0/jsx-dev-runtime.d.ts +0 -44
- package/node_modules/@types/react/ts5.0/jsx-runtime.d.ts +0 -35
- package/node_modules/@types/react/ts5.0/v18/global.d.ts +0 -160
- package/node_modules/@types/react/ts5.0/v18/index.d.ts +0 -4543
- package/node_modules/@types/react/ts5.0/v18/jsx-dev-runtime.d.ts +0 -45
- package/node_modules/@types/react/ts5.0/v18/jsx-runtime.d.ts +0 -36
- package/node_modules/@types/react/ts5.0/v18/ts5.0/global.d.ts +0 -160
- package/node_modules/@types/react/ts5.0/v18/ts5.0/index.d.ts +0 -4530
- package/node_modules/@types/react/ts5.0/v18/ts5.0/jsx-dev-runtime.d.ts +0 -44
- package/node_modules/@types/react/ts5.0/v18/ts5.0/jsx-runtime.d.ts +0 -35
- package/src/index.ts +0 -36
- package/src/useBoolean/index.ts +0 -1
- package/src/useBoolean/useBoolean.ts +0 -50
- package/src/useClickAnyWhere/index.ts +0 -1
- package/src/useClickAnyWhere/useClickAnyWhere.ts +0 -22
- package/src/useCopyToClipboard/index.ts +0 -1
- package/src/useCopyToClipboard/useCopyToClipboard.ts +0 -58
- package/src/useCountdown/index.ts +0 -1
- package/src/useCountdown/useCountdown.ts +0 -102
- package/src/useCounter/index.ts +0 -1
- package/src/useCounter/useCounter.ts +0 -52
- package/src/useDarkMode/index.ts +0 -1
- package/src/useDarkMode/useDarkMode.ts +0 -92
- package/src/useDebounceCallback/index.ts +0 -2
- package/src/useDebounceCallback/useDebounceCallback.ts +0 -115
- package/src/useDebounceValue/index.ts +0 -1
- package/src/useDebounceValue/useDebounceValue.ts +0 -67
- package/src/useDocumentTitle/index.ts +0 -1
- package/src/useDocumentTitle/useDocumentTitle.ts +0 -43
- package/src/useEventCallback/index.ts +0 -1
- package/src/useEventCallback/useEventCallback.ts +0 -40
- package/src/useEventListener/index.ts +0 -1
- package/src/useEventListener/useEventListener.ts +0 -121
- package/src/useHover/index.ts +0 -1
- package/src/useHover/useHover.ts +0 -37
- package/src/useIntersectionObserver/index.ts +0 -1
- package/src/useIntersectionObserver/useIntersectionObserver.ts +0 -186
- package/src/useInterval/index.ts +0 -1
- package/src/useInterval/useInterval.ts +0 -43
- package/src/useIsClient/index.ts +0 -1
- package/src/useIsClient/useIsClient.ts +0 -22
- package/src/useIsMobile/index.ts +0 -2
- package/src/useIsMobile/types.ts +0 -3
- package/src/useIsMobile/useIsMobile.tsx +0 -23
- package/src/useIsMounted/index.ts +0 -1
- package/src/useIsMounted/useIsMounted.ts +0 -15
- package/src/useIsomorphicLayoutEffect/index.ts +0 -1
- package/src/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.ts +0 -17
- package/src/useLocalStorage/index.ts +0 -1
- package/src/useLocalStorage/useLocalStorage.ts +0 -191
- package/src/useLockBody/index.ts +0 -1
- package/src/useLockBody/useLockBody.tsx +0 -12
- package/src/useMap/index.ts +0 -1
- package/src/useMap/useMap.ts +0 -83
- package/src/useMediaQuery/index.ts +0 -1
- package/src/useMediaQuery/useMediaQuery.ts +0 -83
- package/src/useOnClickOutside/index.ts +0 -1
- package/src/useOnClickOutside/useOnClickOutside.ts +0 -61
- package/src/useQueryString/index.ts +0 -1
- package/src/useQueryString/useQueryString.ts +0 -26
- package/src/useReadLocalStorage/index.ts +0 -1
- package/src/useReadLocalStorage/useReadLocalStorage.ts +0 -122
- package/src/useResizeObserver/index.ts +0 -1
- package/src/useResizeObserver/useResizeObserver.ts +0 -131
- package/src/useScreen/index.ts +0 -1
- package/src/useScreen/useScreen.ts +0 -106
- package/src/useScript/index.ts +0 -1
- package/src/useScript/useScript.ts +0 -142
- package/src/useScrollLock/index.ts +0 -1
- package/src/useScrollLock/useScrollLock.ts +0 -141
- package/src/useSessionStorage/index.ts +0 -1
- package/src/useSessionStorage/useSessionStorage.ts +0 -191
- package/src/useStep/index.ts +0 -1
- package/src/useStep/useStep.ts +0 -83
- package/src/useTernaryDarkMode/index.ts +0 -1
- package/src/useTernaryDarkMode/useTernaryDarkMode.ts +0 -81
- package/src/useTimeout/index.ts +0 -1
- package/src/useTimeout/useTimeout.ts +0 -44
- package/src/useToggle/index.ts +0 -1
- package/src/useToggle/useToggle.ts +0 -30
- package/src/useUnmount/index.ts +0 -1
- package/src/useUnmount/useUnmount.ts +0 -26
- package/src/useWindowSize/index.ts +0 -1
- package/src/useWindowSize/useWindowSize.ts +0 -100
- package/tsconfig.json +0 -10
- package/tsconfig.lib.json +0 -33
- package/vite.config.ts +0 -62
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.d.ts.map → index.d.ts.map} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/useBoolean → useBoolean}/index.d.ts +0 -0
- /package/{dist/useBoolean → useBoolean}/index.d.ts.map +0 -0
- /package/{dist/useBoolean → useBoolean}/index.js +0 -0
- /package/{dist/useBoolean → useBoolean}/useBoolean.d.ts +0 -0
- /package/{dist/useBoolean → useBoolean}/useBoolean.d.ts.map +0 -0
- /package/{dist/useBoolean → useBoolean}/useBoolean.js +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/index.d.ts +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/index.d.ts.map +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/index.js +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/useClickAnyWhere.d.ts +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/useClickAnyWhere.d.ts.map +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/useClickAnyWhere.js +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/index.d.ts +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/index.d.ts.map +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/index.js +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/useCopyToClipboard.d.ts +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/useCopyToClipboard.d.ts.map +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/useCopyToClipboard.js +0 -0
- /package/{dist/useCountdown → useCountdown}/index.d.ts +0 -0
- /package/{dist/useCountdown → useCountdown}/index.d.ts.map +0 -0
- /package/{dist/useCountdown → useCountdown}/index.js +0 -0
- /package/{dist/useCountdown → useCountdown}/useCountdown.d.ts +0 -0
- /package/{dist/useCountdown → useCountdown}/useCountdown.d.ts.map +0 -0
- /package/{dist/useCountdown → useCountdown}/useCountdown.js +0 -0
- /package/{dist/useCounter → useCounter}/index.d.ts +0 -0
- /package/{dist/useCounter → useCounter}/index.d.ts.map +0 -0
- /package/{dist/useCounter → useCounter}/index.js +0 -0
- /package/{dist/useCounter → useCounter}/useCounter.d.ts +0 -0
- /package/{dist/useCounter → useCounter}/useCounter.d.ts.map +0 -0
- /package/{dist/useCounter → useCounter}/useCounter.js +0 -0
- /package/{dist/useDarkMode → useDarkMode}/index.d.ts +0 -0
- /package/{dist/useDarkMode → useDarkMode}/index.d.ts.map +0 -0
- /package/{dist/useDarkMode → useDarkMode}/index.js +0 -0
- /package/{dist/useDarkMode → useDarkMode}/useDarkMode.d.ts +0 -0
- /package/{dist/useDarkMode → useDarkMode}/useDarkMode.d.ts.map +0 -0
- /package/{dist/useDarkMode → useDarkMode}/useDarkMode.js +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/index.d.ts +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/index.d.ts.map +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/index.js +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/useDebounceCallback.d.ts +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/useDebounceCallback.d.ts.map +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/useDebounceCallback.js +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/index.d.ts +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/index.d.ts.map +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/index.js +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/useDebounceValue.d.ts +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/useDebounceValue.d.ts.map +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/useDebounceValue.js +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/index.d.ts +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/index.d.ts.map +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/index.js +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/useDocumentTitle.d.ts +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/useDocumentTitle.d.ts.map +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/useDocumentTitle.js +0 -0
- /package/{dist/useEventCallback → useEventCallback}/index.d.ts +0 -0
- /package/{dist/useEventCallback → useEventCallback}/index.d.ts.map +0 -0
- /package/{dist/useEventCallback → useEventCallback}/index.js +0 -0
- /package/{dist/useEventCallback → useEventCallback}/useEventCallback.d.ts +0 -0
- /package/{dist/useEventCallback → useEventCallback}/useEventCallback.d.ts.map +0 -0
- /package/{dist/useEventCallback → useEventCallback}/useEventCallback.js +0 -0
- /package/{dist/useEventListener → useEventListener}/index.d.ts +0 -0
- /package/{dist/useEventListener → useEventListener}/index.d.ts.map +0 -0
- /package/{dist/useEventListener → useEventListener}/index.js +0 -0
- /package/{dist/useEventListener → useEventListener}/useEventListener.js +0 -0
- /package/{dist/useHover → useHover}/index.d.ts +0 -0
- /package/{dist/useHover → useHover}/index.d.ts.map +0 -0
- /package/{dist/useHover → useHover}/index.js +0 -0
- /package/{dist/useHover → useHover}/useHover.js +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/index.d.ts +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/index.d.ts.map +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/index.js +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/useIntersectionObserver.d.ts +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/useIntersectionObserver.d.ts.map +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/useIntersectionObserver.js +0 -0
- /package/{dist/useInterval → useInterval}/index.d.ts +0 -0
- /package/{dist/useInterval → useInterval}/index.d.ts.map +0 -0
- /package/{dist/useInterval → useInterval}/index.js +0 -0
- /package/{dist/useInterval → useInterval}/useInterval.d.ts +0 -0
- /package/{dist/useInterval → useInterval}/useInterval.d.ts.map +0 -0
- /package/{dist/useInterval → useInterval}/useInterval.js +0 -0
- /package/{dist/useIsClient → useIsClient}/index.d.ts +0 -0
- /package/{dist/useIsClient → useIsClient}/index.d.ts.map +0 -0
- /package/{dist/useIsClient → useIsClient}/index.js +0 -0
- /package/{dist/useIsClient → useIsClient}/useIsClient.d.ts +0 -0
- /package/{dist/useIsClient → useIsClient}/useIsClient.d.ts.map +0 -0
- /package/{dist/useIsClient → useIsClient}/useIsClient.js +0 -0
- /package/{dist/useIsMobile → useIsMobile}/index.d.ts +0 -0
- /package/{dist/useIsMobile → useIsMobile}/index.d.ts.map +0 -0
- /package/{dist/useIsMobile → useIsMobile}/index.js +0 -0
- /package/{dist/useIsMobile → useIsMobile}/types.d.ts +0 -0
- /package/{dist/useIsMobile → useIsMobile}/types.d.ts.map +0 -0
- /package/{dist/useIsMobile → useIsMobile}/types.js +0 -0
- /package/{dist/useIsMobile → useIsMobile}/useIsMobile.d.ts +0 -0
- /package/{dist/useIsMobile → useIsMobile}/useIsMobile.d.ts.map +0 -0
- /package/{dist/useIsMobile → useIsMobile}/useIsMobile.js +0 -0
- /package/{dist/useIsMounted → useIsMounted}/index.d.ts +0 -0
- /package/{dist/useIsMounted → useIsMounted}/index.d.ts.map +0 -0
- /package/{dist/useIsMounted → useIsMounted}/index.js +0 -0
- /package/{dist/useIsMounted → useIsMounted}/useIsMounted.d.ts +0 -0
- /package/{dist/useIsMounted → useIsMounted}/useIsMounted.d.ts.map +0 -0
- /package/{dist/useIsMounted → useIsMounted}/useIsMounted.js +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/index.d.ts +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/index.d.ts.map +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/index.js +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/useIsomorphicLayoutEffect.d.ts +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/useIsomorphicLayoutEffect.d.ts.map +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/useIsomorphicLayoutEffect.js +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/index.d.ts +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/index.d.ts.map +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/index.js +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/useLocalStorage.d.ts +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/useLocalStorage.d.ts.map +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/useLocalStorage.js +0 -0
- /package/{dist/useLockBody → useLockBody}/index.d.ts +0 -0
- /package/{dist/useLockBody → useLockBody}/index.d.ts.map +0 -0
- /package/{dist/useLockBody → useLockBody}/index.js +0 -0
- /package/{dist/useLockBody → useLockBody}/useLockBody.d.ts +0 -0
- /package/{dist/useLockBody → useLockBody}/useLockBody.d.ts.map +0 -0
- /package/{dist/useLockBody → useLockBody}/useLockBody.js +0 -0
- /package/{dist/useMap → useMap}/index.d.ts +0 -0
- /package/{dist/useMap → useMap}/index.d.ts.map +0 -0
- /package/{dist/useMap → useMap}/index.js +0 -0
- /package/{dist/useMap → useMap}/useMap.d.ts +0 -0
- /package/{dist/useMap → useMap}/useMap.d.ts.map +0 -0
- /package/{dist/useMap → useMap}/useMap.js +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/index.d.ts +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/index.d.ts.map +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/index.js +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/useMediaQuery.d.ts +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/useMediaQuery.d.ts.map +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/useMediaQuery.js +0 -0
- /package/{dist/useOnClickOutside → useOnClickOutside}/index.d.ts +0 -0
- /package/{dist/useOnClickOutside → useOnClickOutside}/index.d.ts.map +0 -0
- /package/{dist/useOnClickOutside → useOnClickOutside}/index.js +0 -0
- /package/{dist/useOnClickOutside → useOnClickOutside}/useOnClickOutside.js +0 -0
- /package/{dist/useQueryString → useQueryString}/index.d.ts +0 -0
- /package/{dist/useQueryString → useQueryString}/index.d.ts.map +0 -0
- /package/{dist/useQueryString → useQueryString}/index.js +0 -0
- /package/{dist/useQueryString → useQueryString}/useQueryString.d.ts +0 -0
- /package/{dist/useQueryString → useQueryString}/useQueryString.d.ts.map +0 -0
- /package/{dist/useQueryString → useQueryString}/useQueryString.js +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/index.d.ts +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/index.d.ts.map +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/index.js +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/useReadLocalStorage.d.ts +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/useReadLocalStorage.d.ts.map +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/useReadLocalStorage.js +0 -0
- /package/{dist/useResizeObserver → useResizeObserver}/index.d.ts +0 -0
- /package/{dist/useResizeObserver → useResizeObserver}/index.d.ts.map +0 -0
- /package/{dist/useResizeObserver → useResizeObserver}/index.js +0 -0
- /package/{dist/useResizeObserver → useResizeObserver}/useResizeObserver.js +0 -0
- /package/{dist/useScreen → useScreen}/index.d.ts +0 -0
- /package/{dist/useScreen → useScreen}/index.d.ts.map +0 -0
- /package/{dist/useScreen → useScreen}/index.js +0 -0
- /package/{dist/useScreen → useScreen}/useScreen.d.ts +0 -0
- /package/{dist/useScreen → useScreen}/useScreen.d.ts.map +0 -0
- /package/{dist/useScreen → useScreen}/useScreen.js +0 -0
- /package/{dist/useScript → useScript}/index.d.ts +0 -0
- /package/{dist/useScript → useScript}/index.d.ts.map +0 -0
- /package/{dist/useScript → useScript}/index.js +0 -0
- /package/{dist/useScript → useScript}/useScript.d.ts +0 -0
- /package/{dist/useScript → useScript}/useScript.d.ts.map +0 -0
- /package/{dist/useScript → useScript}/useScript.js +0 -0
- /package/{dist/useScrollLock → useScrollLock}/index.d.ts +0 -0
- /package/{dist/useScrollLock → useScrollLock}/index.d.ts.map +0 -0
- /package/{dist/useScrollLock → useScrollLock}/index.js +0 -0
- /package/{dist/useScrollLock → useScrollLock}/useScrollLock.d.ts +0 -0
- /package/{dist/useScrollLock → useScrollLock}/useScrollLock.d.ts.map +0 -0
- /package/{dist/useScrollLock → useScrollLock}/useScrollLock.js +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/index.d.ts +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/index.d.ts.map +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/index.js +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/useSessionStorage.d.ts +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/useSessionStorage.d.ts.map +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/useSessionStorage.js +0 -0
- /package/{dist/useStep → useStep}/index.d.ts +0 -0
- /package/{dist/useStep → useStep}/index.d.ts.map +0 -0
- /package/{dist/useStep → useStep}/index.js +0 -0
- /package/{dist/useStep → useStep}/useStep.d.ts +0 -0
- /package/{dist/useStep → useStep}/useStep.d.ts.map +0 -0
- /package/{dist/useStep → useStep}/useStep.js +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/index.d.ts +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/index.d.ts.map +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/index.js +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/useTernaryDarkMode.d.ts +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/useTernaryDarkMode.d.ts.map +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/useTernaryDarkMode.js +0 -0
- /package/{dist/useTimeout → useTimeout}/index.d.ts +0 -0
- /package/{dist/useTimeout → useTimeout}/index.d.ts.map +0 -0
- /package/{dist/useTimeout → useTimeout}/index.js +0 -0
- /package/{dist/useTimeout → useTimeout}/useTimeout.d.ts +0 -0
- /package/{dist/useTimeout → useTimeout}/useTimeout.d.ts.map +0 -0
- /package/{dist/useTimeout → useTimeout}/useTimeout.js +0 -0
- /package/{dist/useToggle → useToggle}/index.d.ts +0 -0
- /package/{dist/useToggle → useToggle}/index.d.ts.map +0 -0
- /package/{dist/useToggle → useToggle}/index.js +0 -0
- /package/{dist/useToggle → useToggle}/useToggle.d.ts +0 -0
- /package/{dist/useToggle → useToggle}/useToggle.d.ts.map +0 -0
- /package/{dist/useToggle → useToggle}/useToggle.js +0 -0
- /package/{dist/useUnmount → useUnmount}/index.d.ts +0 -0
- /package/{dist/useUnmount → useUnmount}/index.d.ts.map +0 -0
- /package/{dist/useUnmount → useUnmount}/index.js +0 -0
- /package/{dist/useUnmount → useUnmount}/useUnmount.d.ts +0 -0
- /package/{dist/useUnmount → useUnmount}/useUnmount.d.ts.map +0 -0
- /package/{dist/useUnmount → useUnmount}/useUnmount.js +0 -0
- /package/{dist/useWindowSize → useWindowSize}/index.d.ts +0 -0
- /package/{dist/useWindowSize → useWindowSize}/index.d.ts.map +0 -0
- /package/{dist/useWindowSize → useWindowSize}/index.js +0 -0
- /package/{dist/useWindowSize → useWindowSize}/useWindowSize.d.ts +0 -0
- /package/{dist/useWindowSize → useWindowSize}/useWindowSize.d.ts.map +0 -0
- /package/{dist/useWindowSize → useWindowSize}/useWindowSize.js +0 -0
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import type { Dispatch, SetStateAction } from 'react'
|
|
4
|
-
|
|
5
|
-
import { useEventCallback } from '../useEventCallback'
|
|
6
|
-
import { useEventListener } from '../useEventListener'
|
|
7
|
-
|
|
8
|
-
declare global {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
10
|
-
interface WindowEventMap {
|
|
11
|
-
'local-storage': CustomEvent
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Options for customizing the behavior of serialization and deserialization.
|
|
17
|
-
* @template T - The type of the state to be stored in local storage.
|
|
18
|
-
*/
|
|
19
|
-
type UseLocalStorageOptions<T> = {
|
|
20
|
-
/** A function to serialize the value before storing it. */
|
|
21
|
-
serializer?: (value: T) => string
|
|
22
|
-
/** A function to deserialize the stored value. */
|
|
23
|
-
deserializer?: (value: string) => T
|
|
24
|
-
/**
|
|
25
|
-
* If `true` (default), the hook will initialize reading the local storage. In SSR, you should set it to `false`, returning the initial value initially.
|
|
26
|
-
* @default true
|
|
27
|
-
*/
|
|
28
|
-
initializeWithValue?: boolean
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const IS_SERVER = typeof window === 'undefined'
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Custom hook that uses the [`localStorage API`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) to persist state across page reloads.
|
|
35
|
-
* @template T - The type of the state to be stored in local storage.
|
|
36
|
-
* @param {string} key - The key under which the value will be stored in local storage.
|
|
37
|
-
* @param {T | (() => T)} initialValue - The initial value of the state or a function that returns the initial value.
|
|
38
|
-
* @param {UseLocalStorageOptions<T>} [options] - Options for customizing the behavior of serialization and deserialization (optional).
|
|
39
|
-
* @returns {[T, Dispatch<SetStateAction<T>>, () => void]} A tuple containing the stored value, a function to set the value and a function to remove the key from storage.
|
|
40
|
-
* @public
|
|
41
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-local-storage)
|
|
42
|
-
* @example
|
|
43
|
-
* ```tsx
|
|
44
|
-
* const [count, setCount, removeCount] = useLocalStorage('count', 0);
|
|
45
|
-
* // Access the `count` value, the `setCount` function to update it and `removeCount` function to remove the key from storage.
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export function useLocalStorage<T>(
|
|
49
|
-
key: string,
|
|
50
|
-
initialValue: T | (() => T),
|
|
51
|
-
options: UseLocalStorageOptions<T> = {},
|
|
52
|
-
): [T, Dispatch<SetStateAction<T>>, () => void] {
|
|
53
|
-
const { initializeWithValue = true } = options
|
|
54
|
-
|
|
55
|
-
const serializer = useCallback<(value: T) => string>(
|
|
56
|
-
value => {
|
|
57
|
-
if (options.serializer) {
|
|
58
|
-
return options.serializer(value)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return JSON.stringify(value)
|
|
62
|
-
},
|
|
63
|
-
[options],
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
const deserializer = useCallback<(value: string) => T>(
|
|
67
|
-
value => {
|
|
68
|
-
if (options.deserializer) {
|
|
69
|
-
return options.deserializer(value)
|
|
70
|
-
}
|
|
71
|
-
// Support 'undefined' as a value
|
|
72
|
-
if (value === 'undefined') {
|
|
73
|
-
return undefined as unknown as T
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const defaultValue =
|
|
77
|
-
initialValue instanceof Function ? initialValue() : initialValue
|
|
78
|
-
|
|
79
|
-
let parsed: unknown
|
|
80
|
-
try {
|
|
81
|
-
parsed = JSON.parse(value)
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error('Error parsing JSON:', error)
|
|
84
|
-
return defaultValue // Return initialValue if parsing fails
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return parsed as T
|
|
88
|
-
},
|
|
89
|
-
[options, initialValue],
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
// Get from local storage then
|
|
93
|
-
// parse stored json or return initialValue
|
|
94
|
-
const readValue = useCallback((): T => {
|
|
95
|
-
const initialValueToUse =
|
|
96
|
-
initialValue instanceof Function ? initialValue() : initialValue
|
|
97
|
-
|
|
98
|
-
// Prevent build error "window is undefined" but keep working
|
|
99
|
-
if (IS_SERVER) {
|
|
100
|
-
return initialValueToUse
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
const raw = window.localStorage.getItem(key)
|
|
105
|
-
return raw ? deserializer(raw) : initialValueToUse
|
|
106
|
-
} catch (error) {
|
|
107
|
-
console.warn(`Error reading localStorage key “${key}”:`, error)
|
|
108
|
-
return initialValueToUse
|
|
109
|
-
}
|
|
110
|
-
}, [initialValue, key, deserializer])
|
|
111
|
-
|
|
112
|
-
const [storedValue, setStoredValue] = useState(() => {
|
|
113
|
-
if (initializeWithValue) {
|
|
114
|
-
return readValue()
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return initialValue instanceof Function ? initialValue() : initialValue
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
// Return a wrapped version of useState's setter function that ...
|
|
121
|
-
// ... persists the new value to localStorage.
|
|
122
|
-
const setValue: Dispatch<SetStateAction<T>> = useEventCallback(value => {
|
|
123
|
-
// Prevent build error "window is undefined" but keeps working
|
|
124
|
-
if (IS_SERVER) {
|
|
125
|
-
console.warn(
|
|
126
|
-
`Tried setting localStorage key “${key}” even though environment is not a client`,
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
// Allow value to be a function so we have the same API as useState
|
|
132
|
-
const newValue = value instanceof Function ? value(readValue()) : value
|
|
133
|
-
|
|
134
|
-
// Save to local storage
|
|
135
|
-
window.localStorage.setItem(key, serializer(newValue))
|
|
136
|
-
|
|
137
|
-
// Save state
|
|
138
|
-
setStoredValue(newValue)
|
|
139
|
-
|
|
140
|
-
// We dispatch a custom event so every similar useLocalStorage hook is notified
|
|
141
|
-
window.dispatchEvent(new StorageEvent('local-storage', { key }))
|
|
142
|
-
} catch (error) {
|
|
143
|
-
console.warn(`Error setting localStorage key “${key}”:`, error)
|
|
144
|
-
}
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
const removeValue = useEventCallback(() => {
|
|
148
|
-
// Prevent build error "window is undefined" but keeps working
|
|
149
|
-
if (IS_SERVER) {
|
|
150
|
-
console.warn(
|
|
151
|
-
`Tried removing localStorage key “${key}” even though environment is not a client`,
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const defaultValue =
|
|
156
|
-
initialValue instanceof Function ? initialValue() : initialValue
|
|
157
|
-
|
|
158
|
-
// Remove the key from local storage
|
|
159
|
-
window.localStorage.removeItem(key)
|
|
160
|
-
|
|
161
|
-
// Save state with default value
|
|
162
|
-
setStoredValue(defaultValue)
|
|
163
|
-
|
|
164
|
-
// We dispatch a custom event so every similar useLocalStorage hook is notified
|
|
165
|
-
window.dispatchEvent(new StorageEvent('local-storage', { key }))
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
useEffect(() => {
|
|
169
|
-
setStoredValue(readValue())
|
|
170
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
171
|
-
}, [key])
|
|
172
|
-
|
|
173
|
-
const handleStorageChange = useCallback(
|
|
174
|
-
(event: StorageEvent | CustomEvent) => {
|
|
175
|
-
if ((event as StorageEvent).key && (event as StorageEvent).key !== key) {
|
|
176
|
-
return
|
|
177
|
-
}
|
|
178
|
-
setStoredValue(readValue())
|
|
179
|
-
},
|
|
180
|
-
[key, readValue],
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
// this only works for other documents, not the current one
|
|
184
|
-
useEventListener('storage', handleStorageChange)
|
|
185
|
-
|
|
186
|
-
// this is a custom event, triggered in writeValueToLocalStorage
|
|
187
|
-
// See: useLocalStorage()
|
|
188
|
-
useEventListener('local-storage', handleStorageChange)
|
|
189
|
-
|
|
190
|
-
return [storedValue, setValue, removeValue]
|
|
191
|
-
}
|
package/src/useLockBody/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useLockBody'
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as React from "react"
|
|
2
|
-
|
|
3
|
-
// @see https://usehooks.com/useLockBodyScroll.
|
|
4
|
-
export function useLockBody() {
|
|
5
|
-
React.useLayoutEffect((): (() => void) => {
|
|
6
|
-
const originalStyle: string = window.getComputedStyle(
|
|
7
|
-
document.body
|
|
8
|
-
).overflow
|
|
9
|
-
document.body.style.overflow = "hidden"
|
|
10
|
-
return () => (document.body.style.overflow = originalStyle)
|
|
11
|
-
}, [])
|
|
12
|
-
}
|
package/src/useMap/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useMap'
|
package/src/useMap/useMap.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents the type for either a Map or an array of key-value pairs.
|
|
5
|
-
* @template K - The type of keys in the map.
|
|
6
|
-
* @template V - The type of values in the map.
|
|
7
|
-
*/
|
|
8
|
-
type MapOrEntries<K, V> = Map<K, V> | [K, V][]
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Represents the actions available to interact with the map state.
|
|
12
|
-
* @template K - The type of keys in the map.
|
|
13
|
-
* @template V - The type of values in the map.
|
|
14
|
-
*/
|
|
15
|
-
type UseMapActions<K, V> = {
|
|
16
|
-
/** Set a key-value pair in the map. */
|
|
17
|
-
set: (key: K, value: V) => void
|
|
18
|
-
/** Set all key-value pairs in the map. */
|
|
19
|
-
setAll: (entries: MapOrEntries<K, V>) => void
|
|
20
|
-
/** Remove a key-value pair from the map. */
|
|
21
|
-
remove: (key: K) => void
|
|
22
|
-
/** Reset the map to an empty state. */
|
|
23
|
-
reset: Map<K, V>['clear']
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Represents the return type of the `useMap` hook.
|
|
28
|
-
* We hide some setters from the returned map to disable autocompletion.
|
|
29
|
-
* @template K - The type of keys in the map.
|
|
30
|
-
* @template V - The type of values in the map.
|
|
31
|
-
*/
|
|
32
|
-
type UseMapReturn<K, V> = [
|
|
33
|
-
Omit<Map<K, V>, 'set' | 'clear' | 'delete'>,
|
|
34
|
-
UseMapActions<K, V>,
|
|
35
|
-
]
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Custom hook that manages a key-value [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) state with setter actions.
|
|
39
|
-
* @template K - The type of keys in the map.
|
|
40
|
-
* @template V - The type of values in the map.
|
|
41
|
-
* @param {MapOrEntries<K, V>} [initialState] - The initial state of the map as a Map or an array of key-value pairs (optional).
|
|
42
|
-
* @returns {UseMapReturn<K, V>} A tuple containing the map state and actions to interact with the map.
|
|
43
|
-
* @public
|
|
44
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-map)
|
|
45
|
-
* @example
|
|
46
|
-
* ```tsx
|
|
47
|
-
* const [map, mapActions] = useMap();
|
|
48
|
-
* // Access the `map` state and use `mapActions` to set, remove, or reset entries.
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export function useMap<K, V>(
|
|
52
|
-
initialState: MapOrEntries<K, V> = new Map(),
|
|
53
|
-
): UseMapReturn<K, V> {
|
|
54
|
-
const [map, setMap] = useState(new Map(initialState))
|
|
55
|
-
|
|
56
|
-
const actions: UseMapActions<K, V> = {
|
|
57
|
-
set: useCallback((key, value) => {
|
|
58
|
-
setMap(prev => {
|
|
59
|
-
const copy = new Map(prev)
|
|
60
|
-
copy.set(key, value)
|
|
61
|
-
return copy
|
|
62
|
-
})
|
|
63
|
-
}, []),
|
|
64
|
-
|
|
65
|
-
setAll: useCallback(entries => {
|
|
66
|
-
setMap(() => new Map(entries))
|
|
67
|
-
}, []),
|
|
68
|
-
|
|
69
|
-
remove: useCallback(key => {
|
|
70
|
-
setMap(prev => {
|
|
71
|
-
const copy = new Map(prev)
|
|
72
|
-
copy.delete(key)
|
|
73
|
-
return copy
|
|
74
|
-
})
|
|
75
|
-
}, []),
|
|
76
|
-
|
|
77
|
-
reset: useCallback(() => {
|
|
78
|
-
setMap(() => new Map())
|
|
79
|
-
}, []),
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return [map, actions]
|
|
83
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useMediaQuery'
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect'
|
|
4
|
-
|
|
5
|
-
/** Hook options. */
|
|
6
|
-
type UseMediaQueryOptions = {
|
|
7
|
-
/**
|
|
8
|
-
* The default value to return if the hook is being run on the server.
|
|
9
|
-
* @default false
|
|
10
|
-
*/
|
|
11
|
-
defaultValue?: boolean
|
|
12
|
-
/**
|
|
13
|
-
* If `true` (default), the hook will initialize reading the media query. In SSR, you should set it to `false`, returning `options.defaultValue` or `false` initially.
|
|
14
|
-
* @default true
|
|
15
|
-
*/
|
|
16
|
-
initializeWithValue?: boolean
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const IS_SERVER = typeof window === 'undefined'
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Custom hook that tracks the state of a media query using the [`Match Media API`](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia).
|
|
23
|
-
* @param {string} query - The media query to track.
|
|
24
|
-
* @param {?UseMediaQueryOptions} [options] - The options for customizing the behavior of the hook (optional).
|
|
25
|
-
* @returns {boolean} The current state of the media query (true if the query matches, false otherwise).
|
|
26
|
-
* @public
|
|
27
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-media-query)
|
|
28
|
-
* @example
|
|
29
|
-
* ```tsx
|
|
30
|
-
* const isSmallScreen = useMediaQuery('(max-width: 600px)');
|
|
31
|
-
* // Use `isSmallScreen` to conditionally apply styles or logic based on the screen size.
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export function useMediaQuery(
|
|
35
|
-
query: string,
|
|
36
|
-
{
|
|
37
|
-
defaultValue = false,
|
|
38
|
-
initializeWithValue = true,
|
|
39
|
-
}: UseMediaQueryOptions = {},
|
|
40
|
-
): boolean {
|
|
41
|
-
const getMatches = (query: string): boolean => {
|
|
42
|
-
if (IS_SERVER) {
|
|
43
|
-
return defaultValue
|
|
44
|
-
}
|
|
45
|
-
return window.matchMedia(query).matches
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const [matches, setMatches] = useState<boolean>(() => {
|
|
49
|
-
if (initializeWithValue) {
|
|
50
|
-
return getMatches(query)
|
|
51
|
-
}
|
|
52
|
-
return defaultValue
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
// Handles the change event of the media query.
|
|
56
|
-
function handleChange() {
|
|
57
|
-
setMatches(getMatches(query))
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
useIsomorphicLayoutEffect(() => {
|
|
61
|
-
const matchMedia = window.matchMedia(query)
|
|
62
|
-
|
|
63
|
-
// Triggered at the first client-side load and if query changes
|
|
64
|
-
handleChange()
|
|
65
|
-
|
|
66
|
-
// Use deprecated `addListener` and `removeListener` to support Safari < 14 (#135)
|
|
67
|
-
if (matchMedia.addListener) {
|
|
68
|
-
matchMedia.addListener(handleChange)
|
|
69
|
-
} else {
|
|
70
|
-
matchMedia.addEventListener('change', handleChange)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return () => {
|
|
74
|
-
if (matchMedia.removeListener) {
|
|
75
|
-
matchMedia.removeListener(handleChange)
|
|
76
|
-
} else {
|
|
77
|
-
matchMedia.removeEventListener('change', handleChange)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}, [query])
|
|
81
|
-
|
|
82
|
-
return matches
|
|
83
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useOnClickOutside'
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { RefObject } from 'react'
|
|
2
|
-
|
|
3
|
-
import { useEventListener } from '../useEventListener'
|
|
4
|
-
|
|
5
|
-
/** Supported event types. */
|
|
6
|
-
type EventType =
|
|
7
|
-
| 'mousedown'
|
|
8
|
-
| 'mouseup'
|
|
9
|
-
| 'touchstart'
|
|
10
|
-
| 'touchend'
|
|
11
|
-
| 'focusin'
|
|
12
|
-
| 'focusout'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Custom hook that handles clicks outside a specified element.
|
|
16
|
-
* @template T - The type of the element's reference.
|
|
17
|
-
* @param {RefObject<T> | RefObject<T>[]} ref - The React ref object(s) representing the element(s) to watch for outside clicks.
|
|
18
|
-
* @param {(event: MouseEvent | TouchEvent | FocusEvent) => void} handler - The callback function to be executed when a click outside the element occurs.
|
|
19
|
-
* @param {EventType} [eventType] - The mouse event type to listen for (optional, default is 'mousedown').
|
|
20
|
-
* @param {?AddEventListenerOptions} [eventListenerOptions] - The options object to be passed to the `addEventListener` method (optional).
|
|
21
|
-
* @returns {void}
|
|
22
|
-
* @public
|
|
23
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-on-click-outside)
|
|
24
|
-
* @example
|
|
25
|
-
* ```tsx
|
|
26
|
-
* const containerRef = useRef(null);
|
|
27
|
-
* useOnClickOutside([containerRef], () => {
|
|
28
|
-
* // Handle clicks outside the container.
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export function useOnClickOutside<T extends HTMLElement = HTMLElement>(
|
|
33
|
-
ref: RefObject<T> | RefObject<T>[],
|
|
34
|
-
handler: (event: MouseEvent | TouchEvent | FocusEvent) => void,
|
|
35
|
-
eventType: EventType = 'mousedown',
|
|
36
|
-
eventListenerOptions: AddEventListenerOptions = {},
|
|
37
|
-
): void {
|
|
38
|
-
useEventListener(
|
|
39
|
-
eventType,
|
|
40
|
-
event => {
|
|
41
|
-
const target = event.target as Node
|
|
42
|
-
|
|
43
|
-
// Do nothing if the target is not connected element with document
|
|
44
|
-
if (!target || !target.isConnected) {
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const isOutside = Array.isArray(ref)
|
|
49
|
-
? ref
|
|
50
|
-
.filter(r => Boolean(r.current))
|
|
51
|
-
.every(r => r.current && !r.current.contains(target))
|
|
52
|
-
: ref.current && !ref.current.contains(target)
|
|
53
|
-
|
|
54
|
-
if (isOutside) {
|
|
55
|
-
handler(event)
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
undefined,
|
|
59
|
-
eventListenerOptions,
|
|
60
|
-
)
|
|
61
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./useQueryString"
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
type Nullable<T> = {
|
|
4
|
-
[P in keyof T]: T[P] | null;
|
|
5
|
-
};
|
|
6
|
-
type QueryParamsValue = Nullable<string | number | boolean | undefined>
|
|
7
|
-
type QueryParams = Record<string, QueryParamsValue>
|
|
8
|
-
|
|
9
|
-
export const useQueryString = (searchParams: URLSearchParams) => {
|
|
10
|
-
|
|
11
|
-
const createQueryString = useCallback((baseUrl: string, params: QueryParams) => {
|
|
12
|
-
const newSearchParams = new URLSearchParams(searchParams?.toString());
|
|
13
|
-
|
|
14
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
15
|
-
if (value === null || value === "" || value === undefined) {
|
|
16
|
-
newSearchParams.delete(key);
|
|
17
|
-
} else {
|
|
18
|
-
newSearchParams.set(key, String(value));
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
return `${baseUrl}?${newSearchParams.toString()}`;
|
|
23
|
-
}, [searchParams],);
|
|
24
|
-
|
|
25
|
-
return { createQueryString, };
|
|
26
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useReadLocalStorage'
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import { useEventListener } from '../useEventListener'
|
|
4
|
-
|
|
5
|
-
const IS_SERVER = typeof window === 'undefined'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Represents the type for the options available when reading from local storage.
|
|
9
|
-
* @template T - The type of the stored value.
|
|
10
|
-
*/
|
|
11
|
-
type Options<T, InitializeWithValue extends boolean | undefined> = {
|
|
12
|
-
/** Custom deserializer function to convert the stored string value to the desired type (optional). */
|
|
13
|
-
deserializer?: (value: string) => T
|
|
14
|
-
/** If `true` (default), the hook will initialize reading the local storage. In SSR, you should set it to `false`, returning `undefined` initially. */
|
|
15
|
-
initializeWithValue: InitializeWithValue
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// SSR version
|
|
19
|
-
export function useReadLocalStorage<T>(
|
|
20
|
-
key: string,
|
|
21
|
-
options: Options<T, false>,
|
|
22
|
-
): T | null | undefined
|
|
23
|
-
// CSR version
|
|
24
|
-
export function useReadLocalStorage<T>(
|
|
25
|
-
key: string,
|
|
26
|
-
options?: Partial<Options<T, true>>,
|
|
27
|
-
): T | null
|
|
28
|
-
/**
|
|
29
|
-
* Custom hook that reads a value from [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage), closely related to [`useLocalStorage()`](https://usehooks-ts.com/react-hook/use-local-storage).
|
|
30
|
-
* @template T - The type of the stored value.
|
|
31
|
-
* @param {string} key - The key associated with the value in local storage.
|
|
32
|
-
* @param {Options<T>} [options] - Additional options for reading the value (optional).
|
|
33
|
-
* @returns {T | null | undefined} The stored value, or null if the key is not present or an error occurs.
|
|
34
|
-
* @public
|
|
35
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-read-local-storage)
|
|
36
|
-
* @example
|
|
37
|
-
* ```tsx
|
|
38
|
-
* const storedData = useReadLocalStorage('myKey');
|
|
39
|
-
* // Access the stored data from local storage.
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export function useReadLocalStorage<T>(
|
|
43
|
-
key: string,
|
|
44
|
-
options: Partial<Options<T, boolean>> = {},
|
|
45
|
-
): T | null | undefined {
|
|
46
|
-
let { initializeWithValue = true } = options
|
|
47
|
-
if (IS_SERVER) {
|
|
48
|
-
initializeWithValue = false
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const deserializer = useCallback<(value: string) => T | null>(
|
|
52
|
-
value => {
|
|
53
|
-
if (options.deserializer) {
|
|
54
|
-
return options.deserializer(value)
|
|
55
|
-
}
|
|
56
|
-
// Support 'undefined' as a value
|
|
57
|
-
if (value === 'undefined') {
|
|
58
|
-
return undefined as unknown as T
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let parsed: unknown
|
|
62
|
-
try {
|
|
63
|
-
parsed = JSON.parse(value)
|
|
64
|
-
} catch (error) {
|
|
65
|
-
console.error('Error parsing JSON:', error)
|
|
66
|
-
return null
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return parsed as T
|
|
70
|
-
},
|
|
71
|
-
[options],
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
// Get from local storage then
|
|
75
|
-
// parse stored json or return initialValue
|
|
76
|
-
const readValue = useCallback((): T | null => {
|
|
77
|
-
// Prevent build error "window is undefined" but keep keep working
|
|
78
|
-
if (IS_SERVER) {
|
|
79
|
-
return null
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
const raw = window.localStorage.getItem(key)
|
|
84
|
-
return raw ? deserializer(raw) : null
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.warn(`Error reading localStorage key “${key}”:`, error)
|
|
87
|
-
return null
|
|
88
|
-
}
|
|
89
|
-
}, [key, deserializer])
|
|
90
|
-
|
|
91
|
-
const [storedValue, setStoredValue] = useState(() => {
|
|
92
|
-
if (initializeWithValue) {
|
|
93
|
-
return readValue()
|
|
94
|
-
}
|
|
95
|
-
return undefined
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
// Listen if localStorage changes
|
|
99
|
-
useEffect(() => {
|
|
100
|
-
setStoredValue(readValue())
|
|
101
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
102
|
-
}, [key])
|
|
103
|
-
|
|
104
|
-
const handleStorageChange = useCallback(
|
|
105
|
-
(event: StorageEvent | CustomEvent) => {
|
|
106
|
-
if ((event as StorageEvent).key && (event as StorageEvent).key !== key) {
|
|
107
|
-
return
|
|
108
|
-
}
|
|
109
|
-
setStoredValue(readValue())
|
|
110
|
-
},
|
|
111
|
-
[key, readValue],
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
// this only works for other documents, not the current one
|
|
115
|
-
useEventListener('storage', handleStorageChange)
|
|
116
|
-
|
|
117
|
-
// this is a custom event, triggered in writeValueToLocalStorage
|
|
118
|
-
// See: useLocalStorage()
|
|
119
|
-
useEventListener('local-storage', handleStorageChange)
|
|
120
|
-
|
|
121
|
-
return storedValue
|
|
122
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useResizeObserver'
|