{"id":22663840,"url":"https://github.com/pivanov/use-toggle-visibility","last_synced_at":"2026-01-21T18:06:24.187Z","repository":{"id":244047750,"uuid":"814144914","full_name":"pivanov/use-toggle-visibility","owner":"pivanov","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-12T12:49:22.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T08:02:25.226Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/pivanov.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-12T12:29:26.000Z","updated_at":"2024-06-12T12:49:25.000Z","dependencies_parsed_at":"2024-06-12T16:46:08.091Z","dependency_job_id":"90823164-15da-4c3a-bdf9-a8d6fe64246b","html_url":"https://github.com/pivanov/use-toggle-visibility","commit_stats":null,"previous_names":["pivanov/usetogglevisibility"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pivanov%2Fuse-toggle-visibility","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pivanov%2Fuse-toggle-visibility/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pivanov%2Fuse-toggle-visibility/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pivanov%2Fuse-toggle-visibility/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pivanov","download_url":"https://codeload.github.com/pivanov/use-toggle-visibility/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247989002,"owners_count":21029211,"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":[],"created_at":"2024-12-09T12:45:02.963Z","updated_at":"2026-01-21T18:06:24.157Z","avatar_url":"https://github.com/pivanov.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# @pivanov/use-toggle-visibility\n\nA React hook to toggle the visibility of components.\n\n## Installation\n\nYou can install the package via npm:\n\n```bash\nnpm install @pivanov/use-toggle-visibility\n```\n\nor via yarn:\n\n```bash\nyarn add @pivanov/use-toggle-visibility\n```\n\n## Usage\n\n### Basic Usage\n\nHere's an example of how to use the `useToggleVisibility` hook in your React component:\n\n```tsx\nimport React from 'react';\nimport { useToggleVisibility } from '@pivanov/use-toggle-visibility';\n\nconst MyComponent = (props: { message: string }) =\u003e {\n  return \u003cdiv\u003e{props.message}\u003c/div\u003e;\n};\n\nconst App = () =\u003e {\n  const [ToggledComponent, toggleVisibility, isVisible] = useToggleVisibility(MyComponent, false);\n\n  return (\n    \u003cdiv\u003e\n      \u003cbutton onClick={(e) =\u003e toggleVisibility(e)}\u003e\n        {isVisible ? 'Hide' : 'Show'}\n      \u003c/button\u003e\n      \u003cToggledComponent message=\"Hello, World!\" /\u003e\n    \u003c/div\u003e\n  );\n};\n\nexport default App;\n```\n\n### API\n\n#### `useToggleVisibility`\n\n```typescript\nconst [Component, toggleVisibility, isVisible] = useToggleVisibility(WrappedComponent, initialVisibility);\n```\n\n##### Parameters\n\n- `WrappedComponent`: The component to be toggled.\n- `initialVisibility` (optional): The initial visibility state of the component. Defaults to `false`.\n\n##### Returns\n\n- `Component`: The wrapped component that will be conditionally rendered.\n- `toggleVisibility`: A function to toggle the visibility of the component. It can be called with an optional event and an optional boolean to explicitly set the visibility state.\n- `isVisible`: The current visibility state of the component.\n\n### Contributing\n\nContributions are welcome! Please open an issue or submit a pull request.\n\n### License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpivanov%2Fuse-toggle-visibility","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpivanov%2Fuse-toggle-visibility","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpivanov%2Fuse-toggle-visibility/lists"}