├── .all-contributorsrc ├── .changeset ├── README.md └── config.json ├── .codesandbox └── tasks.json ├── .cspell.json ├── .cursor └── rules │ └── react-hook-yolo.mdc ├── .eslintignore ├── .eslintrc.js ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── actions │ └── ci-setup │ │ └── action.yml ├── assets │ ├── Final_Copy_8.png │ ├── Final_Icon.svg │ ├── Look.png │ ├── favicon-24x24.png │ ├── favicon-24x24.svg │ ├── favicon-32x32.png │ ├── favicon-32x32.svg │ ├── favicon-48x48.png │ ├── favicon-48x48.svg │ ├── icon.png │ ├── icon.svg │ ├── logo-dark.png │ ├── logo-light.png │ ├── rooks.png │ └── rooks.svg ├── powered-by-vercel.svg ├── stale.yml └── workflows │ ├── ci-release.yml │ ├── contributors.yml │ └── pr.yml ├── .gitignore ├── .husky ├── _ │ └── husky.sh └── pre-commit ├── .mergify.yml ├── .nvmrc ├── .prettierignore ├── .prettierrc.json ├── .vscode └── settings.json ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── MAINTENANCE.md ├── README.md ├── apps └── website │ ├── CHANGELOG.md │ ├── content-collections.ts │ ├── content │ └── docs │ │ ├── hooks │ │ ├── meta.json │ │ ├── useArrayState.mdx │ │ ├── useAsyncEffect.mdx │ │ ├── useAudio.mdx │ │ ├── useBoundingclientrect.mdx │ │ ├── useBoundingclientrectRef.mdx │ │ ├── useCountdown.mdx │ │ ├── useCounter.mdx │ │ ├── useDebounce.mdx │ │ ├── useDebounceFn.mdx │ │ ├── useDebouncedValue.mdx │ │ ├── useDeepCompareEffect.mdx │ │ ├── useDidMount.mdx │ │ ├── useDidUpdate.mdx │ │ ├── useDimensionsRef.mdx │ │ ├── useDocumentEventListener.mdx │ │ ├── useDocumentTitle.mdx │ │ ├── useDocumentVisibilityState.mdx │ │ ├── useEffectOnceWhen.mdx │ │ ├── useEventListenerRef.mdx │ │ ├── useFileDropRef.mdx │ │ ├── useFocus.mdx │ │ ├── useFocusWithin.mdx │ │ ├── useForkRef.mdx │ │ ├── useFreshCallback.mdx │ │ ├── useFreshRef.mdx │ │ ├── useFreshTick.mdx │ │ ├── useFullscreen.mdx │ │ ├── useGeolocation.mdx │ │ ├── useGetIsMounted.mdx │ │ ├── useInViewRef.mdx │ │ ├── useInput.mdx │ │ ├── useIntersectionObserverRef.mdx │ │ ├── useIntervalWhen.mdx │ │ ├── useIsDroppingFiles.mdx │ │ ├── useIsomorphicEffect.mdx │ │ ├── useKey.mdx │ │ ├── useKeyBindings.mdx │ │ ├── useKeyRef.mdx │ │ ├── useKeys.mdx │ │ ├── useLifecycleLogger.mdx │ │ ├── useLocalstorageState.mdx │ │ ├── useLockBodyScroll.mdx │ │ ├── useMapState.mdx │ │ ├── useMediaMatch.mdx │ │ ├── useMergeRefs.mdx │ │ ├── useMouse.mdx │ │ ├── useMouseMoveDelta.mdx │ │ ├── useMouseWheelDelta.mdx │ │ ├── useMultiSelectableList.mdx │ │ ├── useMutationObserver.mdx │ │ ├── useMutationObserverRef.mdx │ │ ├── useNativeMapState.mdx │ │ ├── useNavigatorLanguage.mdx │ │ ├── useOnClickRef.mdx │ │ ├── useOnHoverRef.mdx │ │ ├── useOnLongHover.mdx │ │ ├── useOnLongPress.mdx │ │ ├── useOnWindowResize.mdx │ │ ├── useOnWindowScroll.mdx │ │ ├── useOnline.mdx │ │ ├── useOrientation.mdx │ │ ├── useOutsideClick.mdx │ │ ├── useOutsideClickRef.mdx │ │ ├── usePreviousDifferent.mdx │ │ ├── usePreviousImmediate.mdx │ │ ├── usePromise.mdx │ │ ├── useQueueState.mdx │ │ ├── useRaf.mdx │ │ ├── useRefElement.mdx │ │ ├── useRenderCount.mdx │ │ ├── useResizeObserverRef.mdx │ │ ├── useSafeSetState.mdx │ │ ├── useSelect.mdx │ │ ├── useSelectableList.mdx │ │ ├── useSessionstorageState.mdx │ │ ├── useSetState.mdx │ │ ├── useSpeech.mdx │ │ ├── useStackState.mdx │ │ ├── useThrottle.mdx │ │ ├── useTimeTravelState.mdx │ │ ├── useTimeoutWhen.mdx │ │ ├── useToggle.mdx │ │ ├── useUndoRedoState.mdx │ │ ├── useUndoState.mdx │ │ ├── useVibrate.mdx │ │ ├── useVideo.mdx │ │ ├── useWhyDidYouUpdate.mdx │ │ ├── useWillUnmount.mdx │ │ ├── useWindowEventListener.mdx │ │ ├── useWindowScrollPosition.mdx │ │ └── useWindowSize.mdx │ │ └── index.mdx │ ├── dump-contributors.ts │ ├── eslint.config.js │ ├── next.config.ts │ ├── package.json │ ├── postcss.config.mjs │ ├── public │ └── images │ │ └── powered-by-vercel.svg │ ├── source.ts │ ├── src │ ├── app │ │ ├── api │ │ │ └── search │ │ │ │ └── route.tsx │ │ ├── docs │ │ │ ├── [[...slug]] │ │ │ │ └── page.tsx │ │ │ ├── docs.css │ │ │ └── layout.tsx │ │ ├── globals.css │ │ ├── layout.config.tsx │ │ ├── layout.tsx │ │ └── page.tsx │ ├── components │ │ ├── CONTRIBUTORS.md │ │ ├── ClientHighlight.tsx │ │ ├── ClientHightlightWrapper.tsx │ │ ├── ContributorList.tsx │ │ ├── Contributors.tsx │ │ └── contributors-list-data.ts │ ├── pages │ │ ├── _app.tsx.old │ │ ├── _document.tsx.old │ │ ├── docs │ │ │ └── [slug].tsx.old │ │ ├── getting-started.md │ │ ├── home-sandbox.md │ │ ├── index.tsx.old │ │ ├── list-of-hooks.md │ │ └── motivation.md │ ├── providers │ │ └── QueryProvider.tsx │ └── utils │ │ ├── mdxSerialize.ts │ │ └── url.ts │ └── tsconfig.json ├── data ├── docs │ ├── rooks.md │ ├── useArrayState.md │ ├── useAsyncEffect.md │ ├── useAudio.md │ ├── useBoundingclientrect.md │ ├── useBoundingclientrectRef.md │ ├── useCountdown.md │ ├── useCounter.md │ ├── useDebounce.md │ ├── useDebounceFn.md │ ├── useDebouncedValue.md │ ├── useDeepCompareEffect.md │ ├── useDidMount.md │ ├── useDidUpdate.md │ ├── useDimensionsRef.md │ ├── useDocumentEventListener.md │ ├── useDocumentTitle.md │ ├── useDocumentVisibilityState.md │ ├── useEffectOnceWhen.md │ ├── useEventListenerRef.md │ ├── useFileDropRef.md │ ├── useFocus.md │ ├── useFocusWithin.md │ ├── useForkRef.md │ ├── useFreshCallback.md │ ├── useFreshRef.md │ ├── useFreshTick.md │ ├── useFullscreen.md │ ├── useGeolocation.md │ ├── useGetIsMounted.md │ ├── useInViewRef.md │ ├── useInput.md │ ├── useIntersectionObserverRef.md │ ├── useIntervalWhen.md │ ├── useIsDroppingFiles.md │ ├── useIsomorphicEffect.md │ ├── useKey.md │ ├── useKeyBindings.md │ ├── useKeyRef.md │ ├── useKeys.md │ ├── useLifecycleLogger.md │ ├── useLocalstorageState.md │ ├── useLockBodyScroll.md │ ├── useMapState.md │ ├── useMediaMatch.md │ ├── useMergeRefs.md │ ├── useMouse.md │ ├── useMouseMoveDelta.md │ ├── useMouseWheelDelta.md │ ├── useMultiSelectableList.md │ ├── useMutationObserver.md │ ├── useMutationObserverRef.md │ ├── useNativeMapState.md │ ├── useNavigatorLanguage.md │ ├── useOnClickRef.md │ ├── useOnHoverRef.md │ ├── useOnLongHover.md │ ├── useOnLongPress.md │ ├── useOnWindowResize.md │ ├── useOnWindowScroll.md │ ├── useOnline.md │ ├── useOrientation.md │ ├── useOutsideClick.md │ ├── useOutsideClickRef.md │ ├── usePreviousDifferent.md │ ├── usePreviousImmediate.md │ ├── usePromise.md │ ├── useQueueState.md │ ├── useRaf.md │ ├── useRefElement.md │ ├── useRenderCount.md │ ├── useResizeObserverRef.md │ ├── useSafeSetState.md │ ├── useSelect.md │ ├── useSelectableList.md │ ├── useSessionstorageState.md │ ├── useSetState.md │ ├── useSpeech.md │ ├── useStackState.md │ ├── useThrottle.md │ ├── useTimeTravelState.md │ ├── useTimeoutWhen.md │ ├── useToggle.md │ ├── useUndoRedoState.md │ ├── useUndoState.md │ ├── useVibrate.md │ ├── useVideo.md │ ├── useWhyDidYouUpdate.md │ ├── useWillUnmount.md │ ├── useWindowEventListener.md │ ├── useWindowScrollPosition.md │ └── useWindowSize.md └── hooks-list.json ├── i18n └── en.json ├── package.json ├── packages ├── eslint-config │ ├── CHANGELOG.md │ ├── README.md │ ├── base.js │ ├── next.js │ ├── package.json │ └── react-internal.js ├── rooks │ ├── .escheckrc │ ├── .gitignore │ ├── .npmignore │ ├── .size-limit.js │ ├── CHANGELOG.md │ ├── README.md │ ├── build.js │ ├── esbuild.mjs │ ├── eslint.config.mjs │ ├── jest.config.ts │ ├── package.json │ ├── src │ │ ├── __tests__ │ │ │ ├── ErrorBoundary.tsx │ │ │ ├── shared.spec.ts │ │ │ ├── useArrayState.spec.ts │ │ │ ├── useAsyncEffect.spec.ts │ │ │ ├── useAudio.spec.tsx │ │ │ ├── useCountdown.spec.tsx │ │ │ ├── useCounter.spec.tsx │ │ │ ├── useDebounce.spec.tsx │ │ │ ├── useDebounceFn.spec.ts │ │ │ ├── useDebouncedValue.spec.ts │ │ │ ├── useDeepCompareEffect.spec.ts │ │ │ ├── useDidMount.spec.ts │ │ │ ├── useDidUpdate.spec.tsx │ │ │ ├── useDimensionsRef.spec.tsx │ │ │ ├── useDocumentEventListener.spec.tsx │ │ │ ├── useDocumentTitle.spec.ts │ │ │ ├── useDocumentVisibilityState.spec.ts │ │ │ ├── useEffectOnceWhen.spec.tsx │ │ │ ├── useEventListenerRef.spec.tsx │ │ │ ├── useFileDropRef.spec.tsx │ │ │ ├── useFocus.spec.tsx │ │ │ ├── useFocusWithin.spec.tsx │ │ │ ├── useForkRef.spec.tsx │ │ │ ├── useFreshCallback.spec.ts │ │ │ ├── useFreshRef.spec.tsx │ │ │ ├── useFreshTick.spec.tsx │ │ │ ├── useGeolocation.spec.tsx │ │ │ ├── useGetIsMounted.spec.ts │ │ │ ├── useInViewRef.spec.tsx │ │ │ ├── useInput.spec.tsx │ │ │ ├── useIntervalWhen.spec.tsx │ │ │ ├── useIsDroppingFiles.spec.tsx │ │ │ ├── useKey.spec.tsx │ │ │ ├── useKeyBindings.spec.tsx │ │ │ ├── useKeyRef.spec.tsx │ │ │ ├── useKeys.spec.tsx │ │ │ ├── useLifecycleLogger.spec.ts │ │ │ ├── useLocalstorageState.spec.tsx │ │ │ ├── useLockBodyScroll.spec.tsx │ │ │ ├── useMapState.spec.tsx │ │ │ ├── useMediaMatch.spec.tsx │ │ │ ├── useMouse.spec.tsx │ │ │ ├── useMouseMoveDelta.spec.tsx │ │ │ ├── useMouseWheelDelta.spec.tsx │ │ │ ├── useMutationObserver.spec.tsx │ │ │ ├── useMutilSelectableList.spec.ts │ │ │ ├── useNativeMapState.spec.ts │ │ │ ├── useNavigatorLanguage.spec.tsx │ │ │ ├── useOnClickRef.spec.tsx │ │ │ ├── useOnHoverRef.spec.tsx │ │ │ ├── useOnLongHover.spec.tsx │ │ │ ├── useOnLongPress.spec.tsx │ │ │ ├── useOnWindowResize.spec.ts │ │ │ ├── useOnWindowScroll.spec.ts │ │ │ ├── useOnline.spec.tsx │ │ │ ├── useOrientation.spec.tsx │ │ │ ├── useOutsideClick.spec.tsx │ │ │ ├── useOutsideClickRef.spec.tsx │ │ │ ├── usePreviousDifferent.spec.ts │ │ │ ├── usePreviousImmediate.spec.ts │ │ │ ├── usePromise.spec.ts │ │ │ ├── useQueueState.spec.ts │ │ │ ├── useRaf.spec.tsx │ │ │ ├── useRenderCount.spec.ts │ │ │ ├── useResizeObserver.spec.tsx │ │ │ ├── useSafeSetState.spec.ts │ │ │ ├── useSelctableList.spec.ts │ │ │ ├── useSelect.spec.ts │ │ │ ├── useSessionstorageState.spec.tsx │ │ │ ├── useSetState.spec.ts │ │ │ ├── useSpeech.spec.ts │ │ │ ├── useStackState.spec.ts │ │ │ ├── useThrottle.spec.tsx │ │ │ ├── useTimeTravelState.spec.ts │ │ │ ├── useTimeoutWhen.spec.ts │ │ │ ├── useToggle.spec.tsx │ │ │ ├── useUndoRedoState.spec.ts │ │ │ ├── useUndoState.spec.tsx │ │ │ ├── useVibrate.spec.ts │ │ │ ├── useVideo.spec.tsx │ │ │ ├── useWarningOnMountInDevelopment.spec.ts │ │ │ ├── useWhyDidYouUpdate.spec.tsx │ │ │ ├── useWillUnmount.spec.tsx │ │ │ ├── useWindowEventListener.spec.tsx │ │ │ ├── useWindowScrollPosition.spec.ts │ │ │ └── useWindowSize.spec.tsx │ │ ├── hooks │ │ │ ├── useArrayState.ts │ │ │ ├── useAsyncEffect.ts │ │ │ ├── useAudio.ts │ │ │ ├── useBoundingclientrect.ts │ │ │ ├── useBoundingclientrectRef.ts │ │ │ ├── useCountdown.ts │ │ │ ├── useCounter.ts │ │ │ ├── useDebounce.ts │ │ │ ├── useDebounceFn.ts │ │ │ ├── useDebouncedValue.ts │ │ │ ├── useDeepCompareEffect.ts │ │ │ ├── useDidMount.ts │ │ │ ├── useDidUpdate.ts │ │ │ ├── useDimensionsRef.ts │ │ │ ├── useDocumentEventListener.ts │ │ │ ├── useDocumentTitle.ts │ │ │ ├── useDocumentVisibilityState.ts │ │ │ ├── useEffectOnceWhen.ts │ │ │ ├── useEventListenerRef.ts │ │ │ ├── useFileDropRef.ts │ │ │ ├── useFocus.ts │ │ │ ├── useFocusWithin.ts │ │ │ ├── useForkRef.ts │ │ │ ├── useFreshCallback.ts │ │ │ ├── useFreshRef.ts │ │ │ ├── useFreshTick.ts │ │ │ ├── useFullscreen.ts │ │ │ ├── useGeolocation.ts │ │ │ ├── useGetIsMounted.ts │ │ │ ├── useGlobalObjectEventListener.ts │ │ │ ├── useInViewRef.ts │ │ │ ├── useInput.ts │ │ │ ├── useIntersectionObserverRef.ts │ │ │ ├── useIntervalWhen.ts │ │ │ ├── useIsDroppingFiles.ts │ │ │ ├── useIsomorphicEffect.ts │ │ │ ├── useKey.ts │ │ │ ├── useKeyBindings.ts │ │ │ ├── useKeyRef.ts │ │ │ ├── useKeys.ts │ │ │ ├── useLifecycleLogger.ts │ │ │ ├── useLocalstorageState.ts │ │ │ ├── useLockBodyScroll.ts │ │ │ ├── useMapState.ts │ │ │ ├── useMediaMatch.ts │ │ │ ├── useMergeRefs.ts │ │ │ ├── useMouse.ts │ │ │ ├── useMouseMoveDelta.ts │ │ │ ├── useMouseWheelDelta.ts │ │ │ ├── useMultiSelectableList.ts │ │ │ ├── useMutationObserver.ts │ │ │ ├── useMutationObserverRef.ts │ │ │ ├── useNativeMapState.ts │ │ │ ├── useNavigatorLanguage.ts │ │ │ ├── useOnClickRef.ts │ │ │ ├── useOnHoverRef.ts │ │ │ ├── useOnLongHover.ts │ │ │ ├── useOnLongPress.ts │ │ │ ├── useOnWindowResize.ts │ │ │ ├── useOnWindowScroll.ts │ │ │ ├── useOnline.ts │ │ │ ├── useOrientation.ts │ │ │ ├── useOutsideClick.ts │ │ │ ├── useOutsideClickRef.ts │ │ │ ├── usePreviousDifferent.ts │ │ │ ├── usePreviousImmediate.ts │ │ │ ├── usePromise.ts │ │ │ ├── useQueueState.ts │ │ │ ├── useRaf.ts │ │ │ ├── useRefElement.ts │ │ │ ├── useRenderCount.ts │ │ │ ├── useResizeObserverRef.ts │ │ │ ├── useSafeSetState.ts │ │ │ ├── useSelect.ts │ │ │ ├── useSelectableList.ts │ │ │ ├── useSessionstorageState.ts │ │ │ ├── useSetState.ts │ │ │ ├── useSpeech.ts │ │ │ ├── useStackState.ts │ │ │ ├── useThrottle.ts │ │ │ ├── useTimeTravelState.ts │ │ │ ├── useTimeoutWhen.ts │ │ │ ├── useToggle.ts │ │ │ ├── useUndoRedoState.ts │ │ │ ├── useUndoState.ts │ │ │ ├── useVibrate.ts │ │ │ ├── useVideo.ts │ │ │ ├── useWarningOnMountInDevelopment.ts │ │ │ ├── useWhyDidYouUpdate.ts │ │ │ ├── useWillUnmount.ts │ │ │ ├── useWindowEventListener.ts │ │ │ ├── useWindowScrollPosition.ts │ │ │ ├── useWindowSize.ts │ │ │ └── warning.ts │ │ ├── index-standalone.ts │ │ ├── index.ts │ │ ├── jest.setup.ts │ │ ├── types │ │ │ ├── index-value.ts │ │ │ ├── types.ts │ │ │ └── utils.ts │ │ └── utils │ │ │ ├── doesIdentifierMatchKeyboardEvent.ts │ │ │ ├── domrect-polyfill.ts │ │ │ ├── noop.ts │ │ │ └── utils.ts │ ├── tsconfig.build.json │ ├── tsconfig.e2e.json │ └── tsconfig.json └── typescript-config │ ├── CHANGELOG.md │ ├── base.json │ ├── nextjs.json │ ├── package.json │ └── react-library.json ├── pnpm-lock.yaml ├── pnpm-workspace.yaml ├── prettier.config.cjs ├── scripts ├── .eslintrc ├── bump-peer-dep-ranges.js ├── create │ ├── addHookToListAndUpdate.mjs │ └── index.mjs ├── docs │ ├── index.ts │ ├── parse-readme.ts │ ├── remove-top-heading.ts │ └── transform-headings.ts ├── update-all-contributors │ └── index.mjs └── update-package-list-to-markdown │ └── index.mjs ├── static ├── css │ └── custom.css └── img │ ├── favicon.ico │ ├── oss_logo.png │ ├── rooks-logo.png │ ├── undraw_code_review.svg │ ├── undraw_monitor.svg │ ├── undraw_note_list.svg │ ├── undraw_online.svg │ ├── undraw_open_source.svg │ ├── undraw_operating_system.svg │ ├── undraw_react.svg │ ├── undraw_tweetstorm.svg │ └── undraw_youtube_tutorial.svg ├── template ├── Examples.md ├── README.md ├── index.spec.template ├── index.template ├── shared.template └── title-card.svg └── turbo.json /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.1.0/schema.json", 3 | "changelog": [ 4 | "@changesets/changelog-github", 5 | { "repo": "imbhargav5/rooks" } 6 | ], 7 | "commit": false, 8 | "fixed": [], 9 | "linked": [], 10 | "access": "restricted", 11 | "baseBranch": "main", 12 | "updateInternalDependencies": "patch", 13 | "ignore": [] 14 | } 15 | -------------------------------------------------------------------------------- /.codesandbox/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // These tasks will run in order when initializing your CodeSandbox project. 3 | "setupTasks": [ 4 | { 5 | "name": "Install Dependencies", 6 | "command": "yarn install" 7 | } 8 | ], 9 | 10 | // These tasks can be run from CodeSandbox. Running one will open a log in the app. 11 | "tasks": { 12 | "build": { 13 | "name": "build", 14 | "command": "yarn build", 15 | "runAtStart": false 16 | }, 17 | "dev": { 18 | "name": "dev", 19 | "command": "yarn dev", 20 | "runAtStart": true 21 | }, 22 | "lint": { 23 | "name": "lint", 24 | "command": "yarn lint", 25 | "runAtStart": false 26 | }, 27 | "clean": { 28 | "name": "clean", 29 | "command": "yarn clean", 30 | "runAtStart": false 31 | }, 32 | "format": { 33 | "name": "format", 34 | "command": "yarn format", 35 | "runAtStart": false 36 | }, 37 | "test": { 38 | "name": "test", 39 | "command": "yarn test", 40 | "runAtStart": false 41 | }, 42 | "start": { 43 | "name": "start", 44 | "command": "yarn start", 45 | "runAtStart": false 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /.cspell.json: -------------------------------------------------------------------------------- 1 | { 2 | "allowCompoundWords": true, 3 | "ignoreRegExpList": ["/.*[0-9].*/"], 4 | "language": "en", 5 | "minWordLength": 5, 6 | "version": "0.2", 7 | "words": [ 8 | "Codecov", 9 | "contributorsrc", 10 | "data-testid", 11 | "imbhargav5", 12 | "jsdelivr", 13 | "jsvalue", 14 | "localstorage", 15 | "Mdast", 16 | "nextui", 17 | "nocheck", 18 | "tsconfigs", 19 | "tspaths", 20 | "unoptimized", 21 | "updation" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | *.d.ts -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | // This tells ESLint to load the config from the package `eslint-config-custom` 4 | extends: ["custom"], 5 | settings: { 6 | next: { 7 | rootDir: ["apps/*/"], 8 | }, 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | name: Bug report 4 | about: Create a report to help us improve 5 | ---**Describe the bug** 6 | A clear and concise description of what the bug is. 7 | 8 | **To Reproduce** 9 | Steps to reproduce the behavior: 10 | 11 | 1. Go to '...' 12 | 2. Click on '....' 13 | 3. Scroll down to '....' 14 | 4. See error 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Screenshots** 20 | If applicable, add screenshots to help explain your problem. 21 | 22 | **Desktop (please complete the following information):** 23 | 24 | - OS: [e.g. iOS] 25 | - Browser [e.g. chrome, safari] 26 | - Version [e.g. 22] 27 | 28 | **Smartphone (please complete the following information):** 29 | 30 | - Device: [e.g. iPhone6] 31 | - OS: [e.g. iOS8.1] 32 | - Browser [e.g. stock browser, safari] 33 | - Version [e.g. 22] 34 | 35 | **Additional context** 36 | Add any other context about the problem here. 37 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | name: Feature request 4 | about: Suggest an idea for this project 5 | ---**Is your feature request related to a problem? Please describe.** 6 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 7 | 8 | **Describe the solution you'd like** 9 | A clear and concise description of what you want to happen. 10 | 11 | **Describe alternatives you've considered** 12 | A clear and concise description of any alternative solutions or features you've considered. 13 | 14 | **Additional context** 15 | Add any other context or screenshots about the feature request here. 16 | -------------------------------------------------------------------------------- /.github/actions/ci-setup/action.yml: -------------------------------------------------------------------------------- 1 | name: "CI setup" 2 | description: "Sets up Node.js, pnpm, and caches dependencies" 3 | runs: 4 | using: "composite" 5 | steps: 6 | - name: Use Node.js 22.x 7 | uses: actions/setup-node@v4 8 | with: 9 | node-version: 22.x 10 | - name: Setup pnpm 11 | uses: pnpm/action-setup@v4 12 | - name: Get pnpm store directory 13 | id: pnpm-cache 14 | run: | 15 | echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT 16 | shell: bash 17 | - uses: actions/cache@v4 18 | id: pnpm-cache-hit 19 | with: 20 | path: | 21 | ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} 22 | node_modules 23 | */*/node_modules 24 | key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} 25 | - name: Install project dependencies 26 | if: steps.pnpm-cache-hit.outputs.cache-hit != 'true' 27 | run: pnpm install 28 | shell: bash 29 | -------------------------------------------------------------------------------- /.github/assets/Final_Copy_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imbhargav5/rooks/1bb63d1ddcda759ff4b768e5511a3258721deefd/.github/assets/Final_Copy_8.png -------------------------------------------------------------------------------- /.github/assets/Look.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imbhargav5/rooks/1bb63d1ddcda759ff4b768e5511a3258721deefd/.github/assets/Look.png -------------------------------------------------------------------------------- /.github/assets/favicon-24x24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imbhargav5/rooks/1bb63d1ddcda759ff4b768e5511a3258721deefd/.github/assets/favicon-24x24.png -------------------------------------------------------------------------------- /.github/assets/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imbhargav5/rooks/1bb63d1ddcda759ff4b768e5511a3258721deefd/.github/assets/favicon-32x32.png -------------------------------------------------------------------------------- /.github/assets/favicon-48x48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imbhargav5/rooks/1bb63d1ddcda759ff4b768e5511a3258721deefd/.github/assets/favicon-48x48.png -------------------------------------------------------------------------------- /.github/assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imbhargav5/rooks/1bb63d1ddcda759ff4b768e5511a3258721deefd/.github/assets/icon.png -------------------------------------------------------------------------------- /.github/assets/logo-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imbhargav5/rooks/1bb63d1ddcda759ff4b768e5511a3258721deefd/.github/assets/logo-dark.png -------------------------------------------------------------------------------- /.github/assets/logo-light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imbhargav5/rooks/1bb63d1ddcda759ff4b768e5511a3258721deefd/.github/assets/logo-light.png -------------------------------------------------------------------------------- /.github/assets/rooks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imbhargav5/rooks/1bb63d1ddcda759ff4b768e5511a3258721deefd/.github/assets/rooks.png -------------------------------------------------------------------------------- /.github/assets/rooks.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | rooks copy 5 | Created with Sketch. 6 | 7 | 8 | 9 | rooks 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | # Label to use when marking an issue as stale 10 | staleLabel: wontfix 11 | # Comment to post when marking an issue as stale. Set to `false` to disable 12 | markComment: > 13 | This issue has been automatically marked as stale because it has not had 14 | recent activity. It will be closed if no further activity occurs. Thank you 15 | for your contributions. 16 | # Comment to post when closing a stale issue. Set to `false` to disable 17 | closeComment: false 18 | -------------------------------------------------------------------------------- /.github/workflows/contributors.yml: -------------------------------------------------------------------------------- 1 | name: All Contributors 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | concurrency: ${{ github.workflow }}-${{ github.ref }} 9 | 10 | jobs: 11 | update-contributors: 12 | if: github.repository == 'imbhargav5/rooks' 13 | 14 | timeout-minutes: 20 15 | 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | - uses: ./.github/actions/ci-setup 21 | # - uses: ./.github/actions/ci-checks 22 | - name: Generate list of contributors 23 | run: | 24 | pnpm contributors:update 25 | pnpm contributors:generate 26 | - name: Auto update Readme 27 | run: | 28 | pnpm update-package-list-to-markdown 29 | - name: Create or Update Pull request 30 | id: cpr 31 | uses: peter-evans/create-pull-request@v4 32 | with: 33 | token: ${{ secrets.GITHUB_TOKEN }} 34 | branch: actions/all-contributors-update 35 | commit-message: Update Contributors List in Readme 36 | title: Update Contributors List in Readme 37 | body: Automatically generating contributors 38 | delete-branch: true 39 | labels: all-contributors-update 40 | draft: false 41 | -------------------------------------------------------------------------------- /.github/workflows/pr.yml: -------------------------------------------------------------------------------- 1 | name: Node CI Pull request 2 | concurrency: 3 | group: pr-${{ github.event.pull_request.number || github.ref }} 4 | cancel-in-progress: true 5 | on: 6 | pull_request: 7 | branches: 8 | - "**" 9 | 10 | jobs: 11 | build: 12 | timeout-minutes: 20 13 | 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: ./.github/actions/ci-setup 19 | - name: run all checks and get coverage 20 | run: pnpm run all-checks 21 | - name: Upload coverage to Codecov 22 | uses: codecov/codecov-action@v2 23 | with: 24 | directory: packages/rooks/src/coverage 25 | size-limit: 26 | timeout-minutes: 20 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@v4 30 | - uses: ./.github/actions/ci-setup 31 | - uses: andresz1/size-limit-action@v1.7.0 32 | with: 33 | directory: "packages/rooks" 34 | github_token: ${{ secrets.GITHUB_TOKEN }} 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | /.package.json 3 | package-lock.json 4 | lib 5 | yarn-error.log 6 | .next 7 | out 8 | dist 9 | lerna-debug.log 10 | .cache 11 | coverage 12 | /*.tsbuildinfo 13 | .out 14 | .DS_Store 15 | yarn-error* 16 | .rpt2_cache 17 | .github/actions/**/node_modules 18 | !.github/actions/**/package-lock.json 19 | *.d.ts 20 | .changelog 21 | **/tsconfig.tsbuildinfo 22 | src/declarations 23 | 24 | 25 | .docusaurus/* 26 | translated_docs 27 | build/ 28 | yarn.lock 29 | i18n/* 30 | 31 | # local env files 32 | .env.local 33 | .env.development.local 34 | .env.test.local 35 | .env.production.local 36 | 37 | # turbo 38 | .turbo 39 | .vercel 40 | 41 | 42 | # content-collections 43 | .content-collections/ 44 | 45 | .jest-cache -------------------------------------------------------------------------------- /.husky/_/husky.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | if [ -z "$husky_skip_init" ]; then 3 | debug () { 4 | if [ "$HUSKY_DEBUG" = "1" ]; then 5 | echo "husky (debug) - $1" 6 | fi 7 | } 8 | 9 | readonly hook_name="$(basename -- "$0")" 10 | debug "starting $hook_name..." 11 | 12 | if [ "$HUSKY" = "0" ]; then 13 | debug "HUSKY env variable is set to 0, skipping hook" 14 | exit 0 15 | fi 16 | 17 | if [ -f ~/.huskyrc ]; then 18 | debug "sourcing ~/.huskyrc" 19 | . ~/.huskyrc 20 | fi 21 | 22 | readonly husky_skip_init=1 23 | export husky_skip_init 24 | sh -e "$0" "$@" 25 | exitCode="$?" 26 | 27 | if [ $exitCode != 0 ]; then 28 | echo "husky - $hook_name hook exited with code $exitCode (error)" 29 | fi 30 | 31 | if [ $exitCode = 127 ]; then 32 | echo "husky - command not found in PATH=$PATH" 33 | fi 34 | 35 | exit $exitCode 36 | fi 37 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | if [[ $IS_GH_ACTION != 1 ]]; then node_modules/.bin/lint-staged; fi; -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | queue_rules: 2 | - name: default 3 | # speculative_checks: 3 4 | # batch_size: 2 5 | conditions: 6 | - check-success=Build (test) 7 | - check-success=Test (yarn test) 8 | pull_request_rules: 9 | - name: update out-of-sync PR 10 | conditions: 11 | - base=master 12 | - -conflict 13 | - -draft 14 | actions: 15 | update: 16 | - name: Automatic merge on approval 17 | conditions: 18 | - "#approved-reviews-by>=1" 19 | actions: 20 | merge: 21 | method: merge 22 | - name: close stale pull request 23 | conditions: 24 | - base=master 25 | - -closed 26 | - updated-at<14 days ago 27 | actions: 28 | close: 29 | message: | 30 | This pull request looks stale. Feel free to reopen it if you think it is a mistake. 31 | - name: merge Renovate pull request 32 | conditions: 33 | - author=renovate[bot] 34 | - label=dependency-update 35 | - label!=major 36 | actions: 37 | review: 38 | type: APPROVE 39 | message: Automatically approving Renovate 40 | queue: 41 | name: default 42 | method: rebase 43 | priority: low 44 | - name: close Renovate pull request (conflict) 45 | conditions: 46 | - conflict 47 | - author=renovate[bot] 48 | - label=dependency-update 49 | actions: 50 | close: 51 | message: | 52 | This automated pull request has a conflict. Closing - Renovate will create a new PR. 53 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 22.14.0 -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | package.json 2 | dist 3 | out 4 | build -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true 5 | } 6 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "eslint.workingDirectories": [ 3 | "./", 4 | { "pattern": "./apps/*/" }, 5 | { "pattern": "./packages/*/" } 6 | ], 7 | "editor.defaultFormatter": "esbenp.prettier-vscode", 8 | "editor.formatOnSave": true, 9 | "editor.codeActionsOnSave": { 10 | "source.fixAll.eslint": "explicit" 11 | }, 12 | "eslint.options": { 13 | "cache": true 14 | }, 15 | "typescript.tsdk": "node_modules/typescript/lib", 16 | "eslint.packageManager": "yarn", 17 | "eslint.validate": [ 18 | "javascript", 19 | "javascriptreact", 20 | "typescript", 21 | "typescriptreact", 22 | "yaml" 23 | ], 24 | "files.exclude": { 25 | "**/.git": true, 26 | "**/.svn": true, 27 | "**/.hg": true, 28 | "**/CVS": true, 29 | "**/.DS_Store": true, 30 | "**/node_modules": false 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | Please check the releases section. 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 react-hooks-org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MAINTENANCE.md: -------------------------------------------------------------------------------- 1 | # Maintenance 2 | 3 | ## Commands for maintaining 4 | 5 | 1. To build custom github actions in ./.github/actions folder 6 | 7 | Run this in the root folder of the project 8 | 9 | ```sh 10 | yarn build:custom-github-actions 11 | ``` 12 | -------------------------------------------------------------------------------- /apps/website/content-collections.ts: -------------------------------------------------------------------------------- 1 | import { defineCollection, defineConfig } from '@content-collections/core'; 2 | import { 3 | createMetaSchema, 4 | createDocSchema, 5 | transformMDX, 6 | } from '@fumadocs/content-collections/configuration'; 7 | 8 | const docs = defineCollection({ 9 | name: 'docs', 10 | directory: 'content/docs', 11 | include: '**/*.mdx', 12 | schema: createDocSchema, 13 | transform: transformMDX, 14 | }); 15 | 16 | const metas = defineCollection({ 17 | name: 'meta', 18 | directory: 'content/docs', 19 | include: '**/meta.json', 20 | parser: 'json', 21 | schema: createMetaSchema, 22 | }); 23 | 24 | export default defineConfig({ 25 | collections: [docs, metas], 26 | }); -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Hooks", 3 | "icon": "Home", 4 | "root": true 5 | } 6 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useArrayState.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useArrayState 3 | title: useArrayState 4 | sidebar_label: useArrayState 5 | --- 6 | 7 | ## About 8 | 9 | Array state manager hook for React. It exposes push**, **pop, unshift, shift, concat, fill and reverse methods to be able to easily modify the state of an array. 10 | 11 | ## Examples 12 | 13 | ```jsx 14 | import { useArrayState, useInput } from "rooks"; 15 | export default function App() { 16 | const [array, controls] = useArrayState([1, 2, 3]); 17 | const numberInput = useInput(0); 18 | 19 | return ( 20 |
21 |

Array items are - {array.join(",")}

22 | 23 | 32 |
33 | ); 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useAsyncEffect.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useAsyncEffect 3 | title: useAsyncEffect 4 | sidebar_label: useAsyncEffect 5 | --- 6 | 7 | ## About 8 | 9 | This is a version of `useEffect` that accepts an async function. 10 | 11 | `useEffect` only works with effect functions that run synchronously. The go-to solution for most people is to simply run an async function inside `useEffect`, but that approach has a lot of gotchas involving React state manipulation. 12 | 13 | [//]: # "Main" 14 | 15 | ## Examples 16 | 17 | ### Basic example 18 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useDebounce.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useDebounce 3 | title: useDebounce 4 | sidebar_label: useDebounce 5 | --- 6 | 7 | ## About 8 | 9 | Debounce hook for react. Internally, it uses lodash debounce. 10 | 11 | ## Examples 12 | 13 | ```jsx 14 | import React, { useState } from "react"; 15 | import { useDebounce } from "rooks"; 16 | 17 | export default function App() { 18 | const [value, setValue] = useState(""); 19 | const setValueDebounced = useDebounce(setValue, 500); 20 | 21 | return ( 22 |
23 | setValueDebounced(e.target.value)} 25 | placeholder="Please type here" 26 | /> 27 |
{value}
28 |
29 | ); 30 | } 31 | ``` 32 | 33 | ### Arguments 34 | 35 | | Argument | Type | Description | Default value | 36 | | -------- | -------- | ---------------------------------------- | ------------- | 37 | | callback | Function | The function to debounce | undefined | 38 | | wait | number | The duration to debounce in milliseconds | undefined | 39 | | options | Object | options to pass into lodash's debounce | {} | 40 | 41 | ### Return Value 42 | 43 | | Name | Type | Description | 44 | | ----------------- | -------- | ---------------------- | 45 | | debouncedFunction | Function | The debounced function | 46 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useDebounceFn.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useDebounceFn 3 | title: useDebounceFn 4 | sidebar_label: useDebounceFn 5 | --- 6 | 7 | ## About 8 | 9 | Powerful debounce function hook for React 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useDebounceFn} from "rooks" 15 | export default function App() { 16 | useDebounceFn(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useDeepCompareEffect.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useDeepCompareEffect 3 | title: useDeepCompareEffect 4 | sidebar_label: useDeepCompareEffect 5 | --- 6 | 7 | ## About 8 | 9 | Deep compare dependencies instead of shallow for useEffect 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useDeepCompareEffect} from "rooks" 15 | export default function App() { 16 | useDeepCompareEffect(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useDidMount.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useDidMount 3 | title: useDidMount 4 | sidebar_label: useDidMount 5 | --- 6 | 7 | ## About 8 | 9 | componentDidMount hook for React 10 |
11 | 12 | ## Examples 13 | 14 | ```jsx 15 | import { useDidMount } from "rooks"; 16 | export default function App() { 17 | useDidMount(function() { 18 | console.log("mounted"); 19 | }); 20 | return null; 21 | } 22 | ``` 23 | 24 | ## Arguments 25 | 26 | | Argument | Type | Description | 27 | | -------- | -------- | ------------------------------ | 28 | | callback | function | function to be called on mount | 29 | 30 | --- 31 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useDidUpdate.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useDidUpdate 3 | title: useDidUpdate 4 | sidebar_label: useDidUpdate 5 | --- 6 | 7 | ## About 8 | 9 | componentDidUpdate hook for react 10 | 11 | ## Examples 12 | 13 | ```jsx 14 | import React, { useState } from "react"; 15 | import { useDidUpdate } from "rooks"; 16 | 17 | export default function App() { 18 | const [value, setValue] = useState(0); 19 | useDidUpdate(() => { 20 | console.log("This message was logged on update."); 21 | }); 22 | return ( 23 |
24 |

Update this value by clicking on the button

25 |

Current value is {value}

26 |

Open the sandbox in codesandbox to view the console

27 | 28 |
29 | ); 30 | } 31 | ``` 32 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useDocumentEventListener.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useDocumentEventListener 3 | title: useDocumentEventListener 4 | sidebar_label: useDocumentEventListener 5 | --- 6 | 7 | ## About 8 | 9 | A react hook to an event listener to the document object 10 | 11 | [//]: # "Main" 12 | 13 | ## Examples 14 | 15 | ```jsx 16 | import { useDocumentEventListener } from "rooks"; 17 | import { useState, useEffect } from "react"; 18 | 19 | export default function App() { 20 | const [myState, setMyState] = useState(0); 21 | 22 | useDocumentEventListener("click", function() { 23 | setMyState(myState + 1); 24 | }); 25 | 26 | return ( 27 |
28 |

useDocumentEventListener Example

29 |

30 |

Clicked {myState} times

31 |
32 | ); 33 | } 34 | ``` 35 | 36 | ### Arguments 37 | 38 | | Arguments | Type | Description | Default value | 39 | | -------------- | -------- | ---------------------------------------------- | ------------- | 40 | | eventName | string | The event to track | undefind | 41 | | callback | function | The callback to be called on event | undefined | 42 | | conditions | object | The options to be passed to the event listener | {} | 43 | | isLayoutEffect | boolean | Should it use layout effect. Defaults to false | false | 44 | 45 | ### Return 46 | 47 | No return value. 48 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useDocumentVisibilityState.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useDocumentVisibilityState 3 | title: useDocumentVisibilityState 4 | sidebar_label: useDocumentVisibilityState 5 | --- 6 | 7 | ## About 8 | 9 | Returns the visibility state of the document. Returns `null` on the server. 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useEffect} from 'react' 15 | import {useDocumentVisibilityState} from "rooks" 16 | 17 | export default function App() { 18 | const isDocumentVisible = useDocumentVisibilityState(); 19 | useEffect(() => { 20 | console.log(isDocumentVisible) 21 | }, [isDocumentVisible]) 22 | return

Try switching to a different tab and check console

23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useEffectOnceWhen.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useEffectOnceWhen 3 | title: useEffectOnceWhen 4 | sidebar_label: useEffectOnceWhen 5 | --- 6 | 7 | ## About 8 | 9 | Runs a callback effect atmost one time when a condition becomes true 10 | 11 | [//]: # "Main" 12 | 13 | ## Examples 14 | 15 | ```jsx 16 | import { useState } from "react"; 17 | import { useEffectOnceWhen } from "rooks"; 18 | 19 | const App = () => { 20 | const [loading, setLoading] = useState(true); 21 | 22 | useEffectOnceWhen(() => { 23 | setTimeout(() => { 24 | setLoading(false); 25 | }, 3000); // Countdown for 3 sec 26 | }, loading); 27 | 28 | return ( 29 |
30 |

Rooks: useEffectOnceWhen Example

31 |
32 | 33 |

34 | {loading 35 | ? "Loading Component (will be gone in 3 secs)...." 36 | : "Counter Component"} 37 |

38 |
39 | ); 40 | }; 41 | 42 | export default App; 43 | ``` 44 | 45 | ### Arguments 46 | 47 | | Arguments | Type | Description | Default value | 48 | | --------- | -------- | ------------------------------------ | ------------- | 49 | | callback | function | The callback to be called | undefined | 50 | | when | boolean | The condition which needs to be true | true | 51 | 52 | ### Return 53 | 54 | No return value. 55 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useFileDropRef.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useFileDropRef 3 | title: useFileDropRef 4 | sidebar_label: useFileDropRef 5 | --- 6 | 7 | ## About 8 | 9 | Drop files easily 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import { useFileDropRef } from "rooks"; 15 | export default function App() { 16 | useFileDropRef(); 17 | return null; 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useFocus.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useFocus 3 | title: useFocus 4 | sidebar_label: useFocus 5 | --- 6 | 7 | ## About 8 | 9 | Handles focus events for the immediate target element. 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import { useFocus } from "rooks"; 15 | export default function App() { 16 | const [isFocus, setIsFocus] = useState(false); 17 | const { focusProps } = useFocus({ 18 | onFocus: () => { 19 | console.log("focus"); 20 | }, 21 | onBlur: () => { 22 | console.log("blur"); 23 | }, 24 | onFocusChange: (isFocused) => { 25 | setIsFocus(isFocused); 26 | }, 27 | }); 28 | 29 | return ( 30 | 39 | ); 40 | } 41 | ``` 42 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useFocusWithin.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useFocusWithin 3 | title: useFocusWithin 4 | sidebar_label: useFocusWithin 5 | --- 6 | 7 | ## About 8 | 9 | Handles focus events for the target component. 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import { useState } from "react"; 15 | import { useFocusWithin } from "rooks"; 16 | 17 | const Page = () => { 18 | const [isFocusWithin, setIsFocusWithin] = useState(false); 19 | const { focusWithinProps } = useFocusWithin({ 20 | onFocusWithin: () => { 21 | console.log("focus within"); 22 | }, 23 | onBlurWithin: () => { 24 | console.log("blur within"); 25 | }, 26 | onFocusWithinChange: (isFocusWithin) => { 27 | setIsFocusWithin(isFocusWithin); 28 | }, 29 | }); 30 | 31 | return ( 32 |
43 | 46 | 49 |
50 | ); 51 | }; 52 | export default Page; 53 | ``` 54 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useFreshCallback.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useFreshCallback 3 | title: useFreshCallback 4 | sidebar_label: useFreshCallback 5 | --- 6 | 7 | ## About 8 | 9 | Avoid stale closures and keep your callback fresh 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useFreshCallback} from "rooks" 15 | export default function App() { 16 | useFreshCallback(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useGetIsMounted.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useGetIsMounted 3 | title: useGetIsMounted 4 | sidebar_label: useGetIsMounted 5 | --- 6 | 7 | ## About 8 | 9 | Checks if a component is mounted or not at the time. Useful for async effects 10 | 11 | [//]: # "Main" 12 | 13 | ## Examples 14 | 15 | ### Basic usage 16 | 17 | ```jsx 18 | import { useEffect } from "react"; 19 | import { useGetIsMounted } from "rooks"; 20 | export default function App() { 21 | const getIsMounted = useGetIsMounted(); 22 | useEffect(() => { 23 | alert("Mounted " + String(getIsMounted())); 24 | }, []); 25 | return null; 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useIsDroppingFiles.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useIsDroppingFiles 3 | title: useIsDroppingFiles 4 | sidebar_label: useIsDroppingFiles 5 | --- 6 | 7 | ## About 8 | 9 | Check if any files are currently being dropped anywhere. Useful for highlighting drop areas. 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import { useIsDroppingFiles } from "rooks"; 15 | export default function App() { 16 | useIsDroppingFiles(); 17 | return null; 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useKeyBindings.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useKeyBindings 3 | title: useKeyBindings 4 | sidebar_label: useKeyBindings 5 | --- 6 | 7 | ## About 8 | 9 | useKeyBindings can bind pairs of keyboard events and handlers. 10 | 11 | [//]: # "Main" 12 | 13 | ## Examples 14 | 15 | ```jsx 16 | import "./styles.css"; 17 | import { useKeyBindings, useCounter } from "rooks"; 18 | 19 | export default function App() { 20 | const { value, increment, incrementBy, decrementBy, reset } = useCounter(0); 21 | const cb1 = () => increment(); 22 | const cb2 = () => decrementBy(3); 23 | const cb3 = () => incrementBy(5); 24 | const cb4 = () => reset(); 25 | 26 | useKeyBindings({ a: cb1, b: cb2, Enter: cb3, Escape: cb4 }); 27 | 28 | return ( 29 |
30 |

31 | Counter value is : {value} 32 |

33 |
34 | ); 35 | } 36 | ``` 37 | 38 | ### Arguments 39 | 40 | | Argument | Type | Description | Default value | 41 | | ----------- | ------- | ------------------------------------- | ------------- | 42 | | keyBindings | Object | pairs of keyboard events and handlers | {} | 43 | | options | Options | refer to useKey | {} | 44 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useLifecycleLogger.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useLifecycleLogger 3 | title: useLifecycleLogger 4 | sidebar_label: useLifecycleLogger 5 | --- 6 | 7 | ## About 8 | 9 | A react hook that console logs parameters as component transitions through lifecycles. 10 | 11 | [//]: # "Main" 12 | 13 | ## Installation 14 | 15 | ## Examples 16 | 17 | ```jsx 18 | import "./styles.css"; 19 | import { useLifecycleLogger } from "rooks"; 20 | import { useEffect, useState } from "react"; 21 | 22 | export default function App() { 23 | const [value, setValue] = useState(0); 24 | 25 | useEffect(() => { 26 | setValue(1); 27 | }, []); 28 | 29 | useLifecycleLogger("Demo", value); 30 | 31 | return ( 32 |
33 |

useLifecycleLogger example

34 |

See console for logs

35 |
36 | ); 37 | } 38 | ``` 39 | 40 | ### Arguments 41 | 42 | | Argument value | Type | Description | Defualt | 43 | | -------------- | ------ | -------------------------------------------------------- | ----------- | 44 | | componentName | String | The name of component to be shown in the log | "Component" | 45 | | rest | Array | An arry of variables to be logged in component lifecycle | undefined | 46 | 47 | ### Returns 48 | 49 | No return value 50 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useLockBodyScroll.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useLockBodyScroll 3 | title: useLockBodyScroll 4 | sidebar_label: useLockBodyScroll 5 | --- 6 | 7 | ## About 8 | 9 | Locks or unlocks body scroll 10 | 11 | ## Examples 12 | 13 | ### Basic 14 | 15 | ```tsx 16 | import { useState } from "react"; 17 | import { useLockBodyScroll } from "rooks"; 18 | 19 | export default function App() { 20 | const [isLocked, setIsLocked] = useState(false); 21 | 22 | // Lock body scroll when isLocked is true 23 | useLockBodyScroll(isLocked); 24 | 25 | return ( 26 |
27 | 30 |
31 | ); 32 | } 33 | ``` 34 | 35 | ## Arguments 36 | 37 | | Argument | Type | Description | 38 | | -------- | ------- | ------------------------------------------------ | 39 | | isLocked | boolean | Whether to lock or unlock scroll on the body tag | 40 | 41 | --- 42 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useMergeRefs.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useMergeRefs 3 | title: useMergeRefs 4 | sidebar_label: useMergeRefs 5 | --- 6 | 7 | ## About 8 | 9 | Merges any number of refs into a single ref 10 | 11 | [//]: # "Main" 12 | 13 | ## Examples 14 | 15 | ```jsx 16 | import "./styles.css"; 17 | import { useMergeRefs, useEventListenerRef } from "rooks"; 18 | 19 | function App() { 20 | const mousedownRef = useEventListenerRef("mousedown", () => { 21 | console.log("mouse down"); 22 | }); 23 | const mouseupRef = useEventListenerRef("mouseup", () => { 24 | console.log("mouse up"); 25 | }); 26 | const refs = useMergeRefs(mousedownRef, mouseupRef); 27 | 28 | return ( 29 |
30 |

Rooks : useMergeRefs Example

31 |
32 |
40 | A div with multiple refs. Click me!! 41 |
42 |
43 | ); 44 | } 45 | export default App; 46 | ``` 47 | 48 | ### Arguments 49 | 50 | | Argument value | Type | Description | 51 | | -------------- | ----- | -------------------------------------------------------------------- | 52 | | refs | Array | Takes any number of refs. Refs can be mutable refs or function refs. | 53 | 54 | ### Returns 55 | 56 | | Return value | Type | Description | 57 | | ------------ | ----------- | ----------- | 58 | | ref | CallbackRef | Merged ref | 59 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useMouse.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useMouse 3 | title: useMouse 4 | sidebar_label: useMouse 5 | --- 6 | 7 | ## About 8 | 9 | ### Description 10 | 11 | Mouse position hook for React. 12 |
13 | 14 | ### Return value 15 | 16 | useMouse returns a single object containing the mouse position. 17 | 18 | | Returned object attributes | Type | Description | 19 | | -------------------------- | ---- | ------------------- | 20 | | x | int | X position of mouse | 21 | | y | int | Y position of mouse | 22 | 23 |
24 | ## Examples 25 | ### Basic Usage 26 | 27 | ```jsx 28 | import { useMouse } from "rooks"; 29 | 30 | export default function App() { 31 | const { x, y } = useMouse(); 32 | return ( 33 | <> 34 |

Move mouse here to see changes to position

35 |

X position is {x || "null"}

36 |

X position is {y || "null"}

37 | 38 | ); 39 | } 40 | ``` 41 | 42 |
43 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useMouseMoveDelta.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useMouseMoveDelta 3 | title: useMouseMoveDelta 4 | sidebar_label: useMouseMoveDelta 5 | --- 6 | 7 | ## About 8 | 9 | Tracks delta of mouse move 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useMouseMoveDelta} from "rooks" 15 | export default function App() { 16 | useMouseMoveDelta(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useMouseWheelDelta.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useMouseWheelDelta 3 | title: useMouseWheelDelta 4 | sidebar_label: useMouseWheelDelta 5 | --- 6 | 7 | ## About 8 | 9 | Tracks delta of mouse move 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useMouseWheelDelta} from "rooks" 15 | export default function App() { 16 | useMouseWheelDelta(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useNativeMapState.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useNativeMapState 3 | title: useNativeMapState 4 | sidebar_label: useNativeMapState 5 | --- 6 | 7 | ## About 8 | 9 | Manage Map() object state in React 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import { useNativeMapState } from "rooks"; 15 | export default function App() { 16 | useNativeMapState(); 17 | return null; 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useNavigatorLanguage.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useNavigatorLanguage 3 | title: useNavigatorLanguage 4 | sidebar_label: useNavigatorLanguage 5 | --- 6 | 7 | ## About 8 | 9 | Navigator Language hook for React. 10 | 11 | ## Examples 12 | 13 | ```jsx 14 | import "./styles.css"; 15 | import { useNavigatorLanguage } from "rooks"; 16 | 17 | function App() { 18 | const language = useNavigatorLanguage(); 19 | 20 | return ( 21 |
24 |

Rooks : useNavigatorLanguage example

25 |

26 | Language is {language} 27 |

28 |
29 | ); 30 | } 31 | 32 | export default App; 33 | ``` 34 | 35 | ### Return value 36 | 37 | A language (String) is returned. 38 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useOnClickRef.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useOnClickRef 3 | title: useOnClickRef 4 | sidebar_label: useOnClickRef 5 | --- 6 | 7 | ## About 8 | 9 | Callback on click/tap events 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import { useOnClickRef } from "rooks"; 15 | export default function App() { 16 | useOnClickRef(); 17 | return null; 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useOnHoverRef.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useOnHoverRef 3 | title: useOnHoverRef 4 | sidebar_label: useOnHoverRef 5 | --- 6 | 7 | ## About 8 | 9 | On hover callback hook 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useOnHoverRef} from "rooks" 15 | export default function App() { 16 | useOnHoverRef(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useOnWindowResize.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useOnWindowResize 3 | title: useOnWindowResize 4 | sidebar_label: useOnWindowResize 5 | --- 6 | 7 | ## About 8 | 9 | A React hook for adding an event listener for window resize 10 | 11 | ## Examples 12 | 13 | ```jsx 14 | import "./styles.css"; 15 | import { useOnWindowResize } from "rooks"; 16 | 17 | export default function App() { 18 | useOnWindowResize(() => console.log("window resized")); 19 | 20 | return ( 21 |
22 |

useOnWindowResize example

23 |

Resize the window and see the logs

24 |
25 | ); 26 | } 27 | ``` 28 | 29 | ### Arguments 30 | 31 | | Arguments | Type | Description | Default value | 32 | | -------------- | -------- | ----------------------------------------------- | ------------- | 33 | | callback | function | Callback function which needs to run on unmount | undefined | 34 | | when | boolean | When the event handler should be active | true | 35 | | isLayoutEffect | boolean | Should it use layout effect. | false | 36 | 37 | ### Returns 38 | 39 | No return value. 40 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useOnline.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useOnline 3 | title: useOnline 4 | sidebar_label: useOnline 5 | --- 6 | 7 | ## About 8 | 9 | Online status hook for React. 10 | 11 | ### Examples 12 | 13 | ```jsx 14 | import "./styles.css"; 15 | import { useOnline } from "rooks"; 16 | 17 | function App() { 18 | const online = useOnline(); 19 | console.log("I'm online"); 20 | 21 | return ( 22 |
23 |

Rooks: useOnline example

24 | 25 |
26 |
27 | Status:You are {online ? "Online" : "Offline"} 28 |
29 |
30 | ); 31 | } 32 | 33 | export default App; 34 | ``` 35 | 36 | ### Return value 37 | 38 | Offline status (boolean) is returned. 39 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useOrientation.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useOrientation 3 | title: useOrientation 4 | sidebar_label: useOrientation 5 | --- 6 | 7 | ## About 8 | 9 | orientation hook for react 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useOrientation} from "rooks" 15 | export default function App() { 16 | useOrientation(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/usePromise.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: usePromise 3 | title: usePromise 4 | sidebar_label: usePromise 5 | --- 6 | 7 | ## About 8 | 9 | Promise management hook for react 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {usePromise} from "rooks" 15 | export default function App() { 16 | usePromise(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useRenderCount.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useRenderCount 3 | title: useRenderCount 4 | sidebar_label: useRenderCount 5 | --- 6 | 7 | ## About 8 | 9 | Get the render count of a component 10 | 11 | ## Examples 12 | 13 | TODO: Add an example here. 14 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useSafeSetState.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useSafeSetState 3 | title: useSafeSetState 4 | sidebar_label: useSafeSetState 5 | --- 6 | 7 | ## About 8 | 9 | set state but ignores if component has already unmounted 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useSafeSetState} from "rooks" 15 | export default function App() { 16 | useSafeSetState(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useSessionstorageState.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useSessionstorageState 3 | title: useSessionstorageState 4 | sidebar_label: useSessionstorageState 5 | --- 6 | 7 | ## About 8 | 9 | useState but syncs with sessionstorage 10 | 11 | [//]: # "Main" 12 | 13 | ## Examples 14 | 15 | ```jsx 16 | import "./styles.css"; 17 | import React from "react"; 18 | import { useSessionstorageState } from "rooks"; 19 | 20 | export default function App() { 21 | const [count, setCount] = useSessionstorageState("my-app:count", 0); 22 | 23 | return ( 24 |
25 |

Rooks : useSessionstorageState

26 |

Refresh the page to see the previous value in tact

27 | 28 | 29 |
30 | ); 31 | } 32 | ``` 33 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useSetState.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useSetState 3 | title: useSetState 4 | sidebar_label: useSetState 5 | --- 6 | 7 | ## About 8 | 9 | Manage the state of a Set in React. Exposes add, delete and clear methods along with the current set to easily manipulate values in a set. 10 | 11 | ## Examples 12 | 13 | ```jsx 14 | import { useSetState } from "rooks"; 15 | export default function App() { 16 | useSetState(); 17 | return null; 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useSpeech.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useSpeech 3 | title: useSpeech 4 | sidebar_label: useSpeech 5 | --- 6 | 7 | ## About 8 | 9 | Speech synthesis hook for React 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useSpeech} from "rooks" 15 | export default function App() { 16 | useSpeech(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useTimeTravelState.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useTimeTravelState 3 | title: useTimeTravelState 4 | sidebar_label: useTimeTravelState 5 | --- 6 | 7 | ## About 8 | 9 | A hook that manages state which can undo and redo. A more powerful version of useUndoState hook. 10 | 11 | ## Examples 12 | 13 | ### Basic example 14 | 15 | ```tsx 16 | import { useTimeTravelState } from "rooks"; 17 | export default function App() { 18 | const [value, setValue, controls] = useTimeTravelState(0); 19 | 20 | return ( 21 |
22 | Current value: {value} 23 |
24 |

25 | Can undo: {String(controls.canUndo)} 26 | Can redo: {String(controls.canRedo)} 27 |

28 |
29 | 30 | 31 | 32 |
33 | ); 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useTimeoutWhen.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useTimeoutWhen 3 | title: useTimeoutWhen 4 | sidebar_label: useTimeoutWhen 5 | --- 6 | 7 | ## About 8 | 9 | Takes a callback and fires it when a condition is true 10 | 11 | [//]: # "Main" 12 | 13 | ## Examples 14 | 15 | ### Basic usage 16 | 17 | ```jsx 18 | import "./styles.css"; 19 | import { useTimeoutWhen } from "rooks"; 20 | import { useState } from "react"; 21 | 22 | function App() { 23 | const [start, setStart] = useState(false); 24 | useTimeoutWhen(() => setStart(false), 2000, start); 25 | return ( 26 | <> 27 |

Rooks: useTimeoutWhen example

28 |
29 |

Click the button below to disable it for 2 seconds

30 | 33 | 34 | ); 35 | } 36 | 37 | export default App; 38 | ``` 39 | 40 | ### Arguments 41 | 42 | | Arguments | Type | Description | Default value | 43 | | --------- | -------- | -------------------------------------------------------- | ------------- | 44 | | callback | function | Function to be executed in timeout | undefind | 45 | | delay | Number | Number in milliseconds after which callback is to be run | 0 | 46 | | when | boolean | The condition which when true, sets the timeout | true | 47 | 48 | ### Returned 49 | 50 | No return value. 51 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useUndoRedoState.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useUndoRedoState 3 | title: useUndoRedoState 4 | sidebar_label: useUndoRedoState 5 | --- 6 | 7 | ## About 8 | 9 | Setstate but can also undo and redo 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useUndoRedoState} from "rooks" 15 | export default function App() { 16 | useUndoRedoState(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useVibrate.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useVibrate 3 | title: useVibrate 4 | sidebar_label: useVibrate 5 | --- 6 | 7 | ## About 8 | 9 | Vibration API hook for React 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useVibrate} from "rooks" 15 | export default function App() { 16 | useVibrate(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useVideo.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useVideo 3 | title: useVideo 4 | sidebar_label: useVideo 5 | --- 6 | 7 | ## About 8 | 9 | Video hook for react 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useVideo} from "rooks" 15 | export default function App() { 16 | useVideo(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useWhyDidYouUpdate.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useWhyDidYouUpdate 3 | title: useWhyDidYouUpdate 4 | sidebar_label: useWhyDidYouUpdate 5 | --- 6 | 7 | ## About 8 | 9 | A hook that can track which value change caused a rerender 10 | 11 | ## Examples 12 | 13 | ```tsx 14 | import {useWhyDidYouUpdate} from "rooks" 15 | export default function App() { 16 | useWhyDidYouUpdate(); 17 | return null 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useWillUnmount.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useWillUnmount 3 | title: useWillUnmount 4 | sidebar_label: useWillUnmount 5 | --- 6 | 7 | ### About 8 | 9 | A React hook for componentWillUnmount lifecycle method. 10 | 11 | ### Examples 12 | 13 | ```jsx 14 | import "./styles.css"; 15 | import { useState } from "react"; 16 | import { useWillUnmount } from "rooks"; 17 | 18 | function Message() { 19 | useWillUnmount(function(props) { 20 | console.log("UNMOUNT", props); 21 | }); 22 | return

This component will unmount

; 23 | } 24 | 25 | const App = () => { 26 | const [shouldRender, enableRender] = useState(true); 27 | return ( 28 |
29 |

Rook: useWillUnmount Example

30 |
31 | 32 |
39 |

40 |

Check or Uncheck the box

41 | enableRender(!shouldRender)} type="checkBox" /> 42 | 43 | {shouldRender && } 44 |
45 |
46 | ); 47 | }; 48 | 49 | export default App; 50 | ``` 51 | 52 | #### Arguments 53 | 54 | | Arguments | Type | Description | Default value | 55 | | --------- | -------- | ----------------------------------------------- | ------------- | 56 | | callback | function | Callback function which needs to run on unmount | undefined | 57 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useWindowEventListener.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useWindowEventListener 3 | title: useWindowEventListener 4 | sidebar_label: useWindowEventListener 5 | --- 6 | 7 | ## About 8 | 9 | Adds an event listener to window 10 | 11 | [//]: # "Main" 12 | 13 | ## Examples 14 | 15 | ### Basic usage 16 | 17 | ```jsx 18 | import { useState } from "react"; 19 | import { useWindowEventListener } from "rooks"; 20 | import "./styles.css"; 21 | 22 | export default function App() { 23 | const [value, setValue] = useState(0); 24 | useWindowEventListener("click", function() { 25 | setValue(value + 1); 26 | }); 27 | return ( 28 |
34 |

Click anywhere

35 |

Value is {value}

36 |
37 | ); 38 | } 39 | ``` 40 | 41 | --- 42 | -------------------------------------------------------------------------------- /apps/website/content/docs/hooks/useWindowScrollPosition.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | id: useWindowScrollPosition 3 | title: useWindowScrollPosition 4 | sidebar_label: useWindowScrollPosition 5 | --- 6 | 7 | ## About 8 | 9 | A React hook to get the scroll position of the window 10 | 11 | [//]: # "Main" 12 | 13 | ## Examples 14 | 15 | ### Basic Usage 16 | 17 | ```jsx 18 | import "./styles.css"; 19 | import { useWindowScrollPosition } from "rooks"; 20 | 21 | function App() { 22 | const position = useWindowScrollPosition(); // default config: { wait = 100, passive = true } 23 | console.log(position); // {x: ..., y: ...} 24 | return ( 25 |
26 |

Rooks : useWindowScrollPosition Example

27 |

28 | 29 |

Scroll

30 |

{JSON.stringify(position)}

31 |
32 | ); 33 | } 34 | 35 | export default App; 36 | ``` 37 | -------------------------------------------------------------------------------- /apps/website/content/docs/index.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Rooks.js 3 | --- 4 | 5 | ## Introduction 6 | 7 | Essential React custom hooks ⚓ to super charge your components! 8 | 9 | ## Contributors 10 | 11 | 12 | -------------------------------------------------------------------------------- /apps/website/dump-contributors.ts: -------------------------------------------------------------------------------- 1 | import { readFileSync, writeFileSync } from 'fs'; 2 | import { join } from 'path'; 3 | import { findUpSync } from 'find-up'; 4 | 5 | const contributorsConfigPath = findUpSync('.all-contributorsrc'); 6 | 7 | if (!contributorsConfigPath) { 8 | throw new Error('.all-contributorsrc file not found'); 9 | } 10 | 11 | const fileToWritePath = join(__dirname, 'src/components/contributors-list-data.ts'); 12 | 13 | const contributorsData = JSON.parse(readFileSync(contributorsConfigPath, 'utf-8')); 14 | 15 | writeFileSync(fileToWritePath, `export const contributorsListData = ${JSON.stringify(contributorsData, null, 2)}`); 16 | 17 | 18 | -------------------------------------------------------------------------------- /apps/website/eslint.config.js: -------------------------------------------------------------------------------- 1 | import { nextJsConfig } from "@repo/eslint-config/next-js"; 2 | 3 | /** @type {import("eslint").Linter.Config} */ 4 | export default nextJsConfig; 5 | -------------------------------------------------------------------------------- /apps/website/next.config.ts: -------------------------------------------------------------------------------- 1 | import { withContentCollections } from '@content-collections/next'; 2 | import { NextConfig } from 'next'; 3 | 4 | const config: NextConfig = { 5 | images: { 6 | domains: ['avatars.githubusercontent.com'], 7 | unoptimized: true, 8 | }, 9 | async redirects() { 10 | return [ 11 | { 12 | source: '/', 13 | destination: '/docs', 14 | permanent: false, 15 | }, 16 | ]; 17 | }, 18 | }; 19 | 20 | export default withContentCollections(config); 21 | -------------------------------------------------------------------------------- /apps/website/postcss.config.mjs: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | "@tailwindcss/postcss": {}, 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /apps/website/source.ts: -------------------------------------------------------------------------------- 1 | import { allDocs, allMetas } from 'content-collections'; 2 | import { loader } from 'fumadocs-core/source'; 3 | import { createMDXSource } from '@fumadocs/content-collections'; 4 | 5 | export const source = loader({ 6 | baseUrl: '/docs', 7 | source: createMDXSource(allDocs, allMetas), 8 | }); -------------------------------------------------------------------------------- /apps/website/src/app/api/search/route.tsx: -------------------------------------------------------------------------------- 1 | import { createFromSource } from 'fumadocs-core/search/server'; 2 | import { source } from '../../../../source'; 3 | 4 | export const { GET } = createFromSource(source); -------------------------------------------------------------------------------- /apps/website/src/app/docs/docs.css: -------------------------------------------------------------------------------- 1 | @import "tailwindcss"; 2 | @import "fumadocs-ui/css/neutral.css"; 3 | @import "fumadocs-ui/css/preset.css"; 4 | 5 | /* path of `fumadocs-ui` relative to the CSS file */ 6 | @source '../../../node_modules/fumadocs-ui/dist/**/*.js'; 7 | -------------------------------------------------------------------------------- /apps/website/src/app/docs/layout.tsx: -------------------------------------------------------------------------------- 1 | import { source } from '../../../source'; 2 | import { DocsLayout } from 'fumadocs-ui/layouts/docs'; 3 | import type { ReactNode } from 'react'; 4 | import { baseOptions } from '../../app/layout.config'; 5 | import './docs.css'; 6 | 7 | export default function Layout({ children }: { children: ReactNode }) { 8 | return ( 9 | 10 | {children} 11 | 12 | ); 13 | } -------------------------------------------------------------------------------- /apps/website/src/app/globals.css: -------------------------------------------------------------------------------- 1 | @import "tailwindcss"; 2 | -------------------------------------------------------------------------------- /apps/website/src/app/layout.config.tsx: -------------------------------------------------------------------------------- 1 | import { BaseLayoutProps } from 'fumadocs-ui/layouts/shared'; 2 | 3 | export const baseOptions: BaseLayoutProps = { 4 | nav: { 5 | title: 'Rooks', 6 | }, 7 | }; -------------------------------------------------------------------------------- /apps/website/src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import { RootProvider } from 'fumadocs-ui/provider'; 2 | import type { ReactNode } from 'react'; 3 | import { QueryProvider } from '../providers/QueryProvider'; 4 | import './globals.css'; 5 | 6 | export default function Layout({ children }: { children: ReactNode }) { 7 | return ( 8 | 9 | 17 | 18 | {children} 19 | 20 | 21 | 22 | ); 23 | } -------------------------------------------------------------------------------- /apps/website/src/app/page.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import { useRouter } from "next/navigation"; 4 | import { useEffect } from "react"; 5 | 6 | export default function Page() { 7 | const router = useRouter(); 8 | useEffect(() => { 9 | router.replace('/docs'); 10 | }, []); 11 | return null; 12 | } 13 | -------------------------------------------------------------------------------- /apps/website/src/components/ClientHightlightWrapper.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | import dynamic from "next/dynamic"; 3 | import { ComponentProps, PropsWithoutRef } from "react"; 4 | 5 | const ClientHighlight = dynamic( 6 | () => import('./ClientHighlight').then(mod => mod.ClientHighlight), 7 | { ssr: false } 8 | ); 9 | 10 | 11 | export function ClientHightlightWrapper(props: ComponentProps) { 12 | return ; 13 | } -------------------------------------------------------------------------------- /apps/website/src/pages/_app.tsx.old: -------------------------------------------------------------------------------- 1 | import { globalCss, NextUIProvider } from "@nextui-org/react"; 2 | import { AppProps } from "next/app"; 3 | import { MDXProvider } from "@mdx-js/react"; 4 | import { components } from "../components/MDXRenderer/components"; 5 | 6 | const globalStyles = globalCss({ 7 | "*": { margin: 0, padding: 0, boxSizing: "border-box" }, 8 | mark: { 9 | backgroundColor: "lightblue", 10 | padding: "2px 6px", 11 | fontWeight: 500, 12 | borderRadius: 6, 13 | }, 14 | hr: { 15 | border: "1px solid $gray-300", 16 | margin: "1rem 0", 17 | }, 18 | br: { 19 | display: "block", 20 | content: "", 21 | margin: "1rem 0", 22 | }, 23 | }); 24 | 25 | function MyApp({ Component, pageProps }: AppProps) { 26 | globalStyles(); 27 | return ( 28 | // 2. Use at the root of your app 29 | 30 | 31 | 32 | 33 | 34 | ); 35 | } 36 | 37 | export default MyApp; 38 | -------------------------------------------------------------------------------- /apps/website/src/pages/_document.tsx.old: -------------------------------------------------------------------------------- 1 | import { Children } from "react"; 2 | import Document, { 3 | Html, 4 | Head, 5 | Main, 6 | NextScript, 7 | DocumentContext, 8 | DocumentInitialProps, 9 | } from "next/document"; 10 | import { CssBaseline } from "@nextui-org/react"; 11 | import { getSandpackCssText } from "@codesandbox/sandpack-react"; 12 | 13 | class MyDocument extends Document { 14 | static async getInitialProps( 15 | ctx: DocumentContext 16 | ): Promise { 17 | const initialProps = await Document.getInitialProps(ctx); 18 | return { 19 | ...initialProps, 20 | styles: <>{Children.toArray([initialProps.styles])}, 21 | }; 22 | } 23 | 24 | render() { 25 | return ( 26 | 27 | 28 | {CssBaseline.flush()}{" "} 29 |