Skip to content

feat: add useDisclosure hook#18

Merged
thepuskar merged 7 commits into
mainfrom
feat/use-disclosure
May 11, 2026
Merged

feat: add useDisclosure hook#18
thepuskar merged 7 commits into
mainfrom
feat/use-disclosure

Conversation

@thepuskar
Copy link
Copy Markdown
Owner

@thepuskar thepuskar commented May 11, 2026

Summary

What does this PR change?

  • Adds a new useDisclosure hook with controlled and uncontrolled usage support.
  • Exports UseDisclosureOptions and UseDisclosureReturn types.
  • Adds stable open, close, toggle, and setOpen callbacks.
  • Ensures onOpen, onClose, and onChange only fire on actual state transitions.
  • Adds Vitest coverage for uncontrolled behavior, controlled behavior, callback behavior, stable references, and SSR safety.
  • Adds a docs page and live docs demo for useDisclosure.
  • Updates hook and docs barrel/meta entries.

Why is it needed?

useDisclosure provides a focused, production-ready primitive for common open/closed UI state such as dialogs, popovers, accordions, details panels, and drawers.

It avoids repeating custom boolean state logic across components while supporting design-system needs like controlled state, uncontrolled defaults, stable action callbacks, transition callbacks, SSR safety, and TypeScript-first exports.

Checklist

  • Tests added/updated
  • npm run lint passes
  • npm run typecheck passes
  • npm run test passes
  • npm run build passes
  • Docs/README updated if API changed

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 11, 2026

Deploying use-kit with  Cloudflare Pages  Cloudflare Pages

Latest commit: 14a2392
Status: ✅  Deploy successful!
Preview URL: https://60539c7d.use-kit.pages.dev
Branch Preview URL: https://feat-use-disclosure.use-kit.pages.dev

View logs

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the useDisclosure hook, which manages boolean state for UI components like dialogs and accordions in both controlled and uncontrolled modes. The PR includes the hook implementation, documentation, a demo component, and comprehensive unit tests. The review feedback identifies several technical improvements for the hook: ensuring the internal state reference is updated in both modes to handle consecutive synchronous updates, memoizing the return object to prevent unnecessary downstream re-renders, and moving ref updates out of the render phase to ensure compatibility with React Concurrent Mode.

Comment thread src/hooks/useDisclosure/useDisclosure.ts
Comment thread src/hooks/useDisclosure/useDisclosure.ts Outdated
Comment thread src/hooks/useDisclosure/useDisclosure.ts
@thepuskar thepuskar self-assigned this May 11, 2026
@thepuskar thepuskar merged commit ceced05 into main May 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant