Skip to content

Conversation

sam3690
Copy link

@sam3690 sam3690 commented Oct 14, 2025

Description

Adds a new useSwitcher hook that provides explicit control functions for boolean state management.

Features

  • Returns a tuple with [state, turnOn, turnOff, toggle]
  • Similar to useToggle but with dedicated functions for better code clarity
  • Default value support (defaults to false)
  • Memoized functions using useCallback for performance

Changes

  • ✅ Implemented useSwitcher hook in src/useSwitcher.ts
  • ✅ Added comprehensive test suite (12 tests, all passing)
  • ✅ Added documentation with examples
  • ✅ Exported hook in main index.ts

Testing

All tests pass:

npm test -- useSwitcher.test.ts
# ✓ 12 tests passing

Example Usage

const [isOpen, openModal, closeModal, toggleModal] = useSwitcher();

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