{"id":15632907,"url":"https://github.com/pacocoursey/use-delayed-render","last_synced_at":"2025-04-06T21:16:05.776Z","repository":{"id":42200882,"uuid":"263535556","full_name":"pacocoursey/use-delayed-render","owner":"pacocoursey","description":"react hook for delaying the render and unmount of a component","archived":false,"fork":false,"pushed_at":"2023-01-07T04:43:32.000Z","size":473,"stargazers_count":165,"open_issues_count":6,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T20:11:19.221Z","etag":null,"topics":["hook","react","react-hooks"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pacocoursey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-13T05:39:06.000Z","updated_at":"2024-10-16T02:15:46.000Z","dependencies_parsed_at":"2023-02-06T12:15:41.128Z","dependency_job_id":null,"html_url":"https://github.com/pacocoursey/use-delayed-render","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacocoursey%2Fuse-delayed-render","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacocoursey%2Fuse-delayed-render/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacocoursey%2Fuse-delayed-render/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacocoursey%2Fuse-delayed-render/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pacocoursey","download_url":"https://codeload.github.com/pacocoursey/use-delayed-render/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247550691,"owners_count":20956987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hook","react","react-hooks"],"created_at":"2024-10-03T10:45:43.763Z","updated_at":"2025-04-06T21:16:05.753Z","avatar_url":"https://github.com/pacocoursey.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# useDelayedRender ![npm bundle size](https://img.shields.io/bundlephobia/minzip/use-delayed-render)\n\nuseDelayedRender is a react hook for delaying the render and unmount of a component. This is commonly used to animate UI on unmount.\n\n\u003cbr /\u003e\n\n## Installation\n\n```\n$ yarn add use-delayed-render\n```\n\n\u003cbr /\u003e\n\n## Usage\n\nFunction signature:\n\n```ts\nconst { mounted: boolean, rendered: boolean } = useDelayedRender(\n  active: boolean,\n  options?: {\n    enterDelay: number,\n    exitDelay: number,\n    onUnmount: () =\u003e void\n  }\n)\n```\n\nOptions:\n\n- `active`: Whether your component is in an active state\n- `enterDelay`: After mounting, the delay before `rendered` becomes true\n- `exitDelay`: After `rendered` becomes false, the delay before unmounting\n- `onUnmount`: A callback triggered after unmounting\n\nReturn values:\n\n- `mounted`: Whether your component should be mounted in the DOM\n- `rendered`: Whether your component should be visible\n\n\u003cbr /\u003e\n\n## Example\n\nRender a modal, but delay the unmount so that our 2 second CSS transition completes before the modal is removed from the DOM.\n\n```js\nconst Modal = ({ active }) =\u003e {\n  const { mounted, rendered } = useDelayedRender(active, {\n    exitDelay: 2000,\n  })\n\n  if (!mounted) return null\n\n  return (\n    \u003cPortal\u003e\n      \u003cdiv className={rendered ? 'modal visible' : 'modal'}\u003e{/* ... */}\u003c/div\u003e\n    \u003c/Portal\u003e\n  )\n}\n```\n\nThis allows you to use simple CSS transitions to animate the mounting/unmounting of your component.\n\n```css\n.modal {\n  opacity: 0;\n  transition: opacity 2s ease;\n}\n\n.modal.visible {\n  opacity: 1;\n}\n```\n\n\u003cbr /\u003e\n\n## Why?\n\n- Usually you would use [`react-transition-group`](https://github.com/reactjs/react-transition-group) to solve this, but the 2.37MB install size is a bit overkill, compared to this package at 491B gzipped.\n\n```jsx\n\u003cTransition in={active} unmountOnExit timeout={200} onExited={handleExit}\u003e\n  \u003cModal /\u003e\n\u003c/Transition\u003e\n```\n\n- Hooks solve the problem without needing a render function or HOC.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacocoursey%2Fuse-delayed-render","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpacocoursey%2Fuse-delayed-render","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacocoursey%2Fuse-delayed-render/lists"}