feat: add useDisclosure hook#18
Merged
Merged
Conversation
Deploying use-kit with
|
| 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 |
There was a problem hiding this comment.
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.
… in useDisclosure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
What does this PR change?
useDisclosurehook with controlled and uncontrolled usage support.UseDisclosureOptionsandUseDisclosureReturntypes.open,close,toggle, andsetOpencallbacks.onOpen,onClose, andonChangeonly fire on actual state transitions.useDisclosure.Why is it needed?
useDisclosureprovides 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
npm run lintpassesnpm run typecheckpassesnpm run testpassesnpm run buildpasses