Hooks
Shared hooks for bridge game logic — auctions, hands, contracts, play, and deal validation.
Import from @workspace/bridge-react/hooks/*.
These hooks are deprecated re-exports that point to their canonical module locations. New code should import from the canonical paths listed below. The ./hooks/* entry point remains for backward compatibility.
All hooks use useBridgeEngine() internally to get variant-specific configuration.
Auction Hooks
useAreAuctionsEnabled
Determines whether auctions are enabled based on teaching configuration.
Canonical import: @workspace/bridge-react/bidding/hooks/use-are-auctions-enabled
import { useAreAuctionsEnabled } from '@workspace/bridge-react/hooks/useAreAuctionsEnabled';
const areEnabled = useAreAuctionsEnabled({ auctionMode, teachDummy });Prop
Type
Returns: boolean
useIsAuctionModeEnabled
Determines whether the auction mode selector should be enabled.
Canonical import: @workspace/bridge-react/bidding/hooks/use-are-auctions-enabled
import { useIsAuctionModeEnabled } from '@workspace/bridge-react/hooks/useAreAuctionsEnabled';
const isEnabled = useIsAuctionModeEnabled(teachDummy);| Parameter | Type | Description |
|---|---|---|
teachDummy | boolean | undefined | Whether the dummy is shown |
Returns: boolean
Pedagogy Mode Hooks
usePedagogyModeGroups
Provides default pedagogy mode groups with labels for the PedagogyModeSelect component.
Canonical import: @workspace/bridge-react/bidding/hooks/use-pedagogy-mode-groups
import { usePedagogyModeGroups } from '@workspace/bridge-react/hooks/usePedagogyModeGroups';
const groups = usePedagogyModeGroups({
groups: { 'with-auction': t('withAuction') },
options: { auction: t('allowAuction') },
});| Parameter | Type | Description |
|---|---|---|
labels | Partial<PedagogyModeGroupLabels> | Optional label overrides for groups and options |
Returns: PedagogyModeGroup[]
usePedagogyModeWithRules
Wraps a pedagogy mode onChange handler to derive variant from the engine.
Canonical import: @workspace/bridge-react/bidding/hooks/use-pedagogy-mode-with-rules
import { usePedagogyModeWithRules } from '@workspace/bridge-react/hooks/usePedagogyModeWithRules';
const handleModeChange = usePedagogyModeWithRules(setPedagogyMode);| Parameter | Type | Description |
|---|---|---|
onChange | (mode: string) => void | The original onChange handler |
Returns: (mode: string) => void
Hand Hooks
useAreHandsComplete
Checks if all hands are complete (have the expected number of cards).
Canonical import: @workspace/bridge-react/hand/hooks/use-are-hands-complete
import { useAreHandsComplete } from '@workspace/bridge-react/hooks/useAreHandsComplete';
const { areComplete, incompletePlayers } = useAreHandsComplete(hands);Prop
Type
useHandsStatus
Gets the complete status of all hands including duplicated cards detection.
Canonical import: @workspace/bridge-react/hand/hooks/use-hands-status
import { useHandsStatus } from '@workspace/bridge-react/hooks/useHandsStatus';
const { areComplete, areEmpty, hasTooManyCards, incompletePlayers, duplicatedCards } = useHandsStatus(hands);Prop
Type
useHandInputState
Manages hand input state with debouncing and formatting. Provides internal state during typing, 300ms debounce, immediate validation on blur, and localized rank formatting via the engine notation context.
Canonical import: @workspace/bridge-react/hand/use-hand-input-state
import { useHandInputState } from '@workspace/bridge-react/hooks/useHandInputState';
const { inputValue, handleChange, handleFocus, handleBlur } = useHandInputState({
value: ['A', 'K', 'Q'],
onChange: (ranks) => setRanks(ranks),
});Prop
Type
Prop
Type
useHandInputValidation
Handles validated hand input with debouncing, formatting, duplicate removal, and rank sorting. Similar to useHandInputState but also filters invalid ranks and sorts by rank order.
Canonical import: @workspace/bridge-react/hand/use-hand-input-validation
import { useHandInputValidation } from '@workspace/bridge-react/hooks/useHandInputValidation';
const { inputValue, onChange, onFocus, onBlur } = useHandInputValidation({
value: ['A', 'K', 'Q'],
onValueChange: (ranks) => setRanks(ranks),
});Prop
Type
Prop
Type
Contract Hooks
useContractResult
Gets the contract result (confirmed or candidate) from a bid sequence.
Canonical import: @workspace/bridge-react/contract/hooks/use-contract-result
import { useContractResult } from '@workspace/bridge-react/hooks/useContractResult';
const { result, declarer, isCandidate } = useContractResult(auctionSequence);Prop
Type
useTrump
Gets the trump suit from a bid sequence. Uses the candidate contract if not yet confirmed.
Canonical import: @workspace/bridge-react/contract/hooks/use-trump
import { useTrump } from '@workspace/bridge-react/hooks/useTrump';
const trump = useTrump(auctionSequence);
// trump = "S" | "H" | "D" | "C" | null| Parameter | Type | Description |
|---|---|---|
sequence | BidInfo[] | Bid sequence |
Returns: Suit | null
Play Hooks
useHasPlayedSuit
Returns a function that checks if a player has played a card of a specific suit across all tricks.
Canonical import: @workspace/bridge-react/play/hooks/use-has-played-suit
import { useHasPlayedSuit } from '@workspace/bridge-react/hooks/useHasPlayedSuit';
const hasPlayedSuit = useHasPlayedSuit(tricks);
const played = hasPlayedSuit('N', 'S'); // Has North played a spade?| Parameter | Type | Description |
|---|---|---|
tricks | GenericTrick[] | Array of tricks (works with both strict types and form data) |
Returns: (player: Player, suit: Suit) => boolean
useLead
Gets the opening lead (first card of the first trick).
Canonical import: @workspace/bridge-react/play/hooks/use-lead
import { useLead } from '@workspace/bridge-react/hooks/useLead';
const lead = useLead(tricks);
// lead = { suit: "S", rank: "A" } | null| Parameter | Type | Description |
|---|---|---|
tricks | Trick[] | Array of tricks from the play state |
Returns: Card | null
useTricksWithWinners
Enriches tricks with computed winners using the bridge engine. Takes display tricks (with nullable cards) and a parsed contract, returns tricks with winner fields populated.
Import: @workspace/bridge-react/play/hooks/useTricksWithWinners
import { useTricksWithWinners } from '@workspace/bridge-react/play/hooks/useTricksWithWinners';
const tricksWithWinners = useTricksWithWinners(tricks, contract);| Parameter | Type | Description |
|---|---|---|
tricks | Trick[] | Array of display tricks from TricksDisplay |
contract | DisplayContract | null | Parsed contract (needed for trump suit) |
Returns: Trick[] — Same tricks with winner computed for each complete trick.
Deal Validation
useValidateDeal
Validates a deal (hands + contract). Takes all data as props with no form dependency.
Import: @workspace/bridge-react/hooks/useValidateDeal (not deprecated — lives in hooks module directly)
import { useValidateDeal } from '@workspace/bridge-react/hooks/useValidateDeal';
const { isValid, errors, result } = useValidateDeal({
hands,
auctionSequence,
areAuctionsEnabled,
});Prop
Type
Prop
Type