Rreact-raffle-picker

API

Every prop, one page.

This is the flat reference — everything the compound API exposes, no clicking through tabs. For a live, interactive version of every prop, use the Storybook or the Playground.

import { RafflePick } from 'react-raffle-picker'

;<RafflePick items={['Alice', 'Bob', 'Carol']} inertia autoStart={false}>
  <RafflePick.Value animation="roll" />
  <RafflePick.Button startLabel="Draw" stopLabel="Stop" />
  <RafflePick.Countdown seconds={5} />
</RafflePick>

<RafflePick>

root

Owns the engine — cycling, phase machine, no-repeat history. Provides context; renders no DOM opinion beyond the wrapper element.

PropTypeDefaultNotes
min, maxnumber1, 100Numeric range. Ignored if items is set.
itemsstring[]Switches to item mode — cycles through names instead of numbers.
intervalnumber100Tick speed in ms, clamped to a minimum of 50.
randombooleantrueRandom pick per tick vs sequential increment.
inertiabooleanfalseSoft-start / soft-stop ramp instead of an instant flip.
autoStartbooleantrueBegin cycling on mount.
noRepeatbooleantrueExcludes previously frozen values from later rounds — no duplicate winners.
initialValuenumber | stringValue shown before the first run.
finalValuenumber | stringForces settle to land on this value while the cycle still looks random.
onSelect(value) => voidFires once per round, when the phase settles to frozen.
onExhausted() => voidFires when start() runs but noRepeat has already drawn every candidate.
asElementType'div'Wrapper element/component.
className, stylestring, CSSPropertiesWrapper class / inline style.
childrenReactNodeCompound sub-components — Value, Button, Countdown, Slots.

<RafflePick.Value>

consumer

Renders the cycling value. Writes textContent imperatively per tick — no React re-render while running. Multiple instances inside one root are supported.

PropTypeDefaultNotes
animation'roll' | 'fade' | 'blur' | 'reel''roll'Opt-in CSS animation, bound to the current tick duration.
asElementType'span'Rendered element.
className, stylestring, CSSPropertiesClass / inline style.

<RafflePick.Button>

consumer

Toggles start / freeze based on the current phase.

PropTypeDefaultNotes
startLabelReactNodeShown in idle / frozen — click starts a round.
stopLabelReactNodeShown in running / starting — click stops.
waitLabelReactNodeShown in settling. Button is disabled.
childrenReactNodeFallback label when no state-specific label is set.
disabledbooleanExternal disable, on top of the automatic disable during settling / when noRepeat is exhausted.
className, stylestring, CSSPropertiesClass / inline style.

<RafflePick.Countdown>

consumer

Schedules auto-freeze after seconds. Renders an SVG ring + numeric label by default.

PropTypeDefaultNotes
secondsnumberRequired. Auto-freeze delay. Renders only while running.
className, stylestring, CSSPropertiesClass / inline style.
children(remaining: number) => ReactNodeRender-prop for fully custom output instead of the built-in ring + label.

<RafflePick.Slots>

consumer

Independent multi-reel slot machine. Each reel ticks on its own and stops with a stagger, left to right.

PropTypeDefaultNotes
lengthnumber3Number of independent reels.
charsstring'0123456789'Charset pool each reel picks from. Emoji-safe.
spinIntervalnumber80Tick rate per reel, ms, clamped ≥ 50.
staggerMsnumber220Delay between consecutive reel stops on settle.
onResult(joined: string) => voidFires when the last reel lands, with the joined result.
className, slotClassNamestringClass for the row wrapper / each individual reel.
style, slotStyleCSSPropertiesInline style for the row wrapper / each reel.

useRaffleContext()

escape hatch

For fully custom renderers. Must be called under <RafflePick> — throws otherwise.

PropTypeDefaultNotes
phase'idle' | 'starting' | 'running' | 'settling' | 'frozen'Current state machine phase.
displayednumber | stringValue to render post-freeze / pre-cycle.
noRepeat, exhausted, remainingboolean, boolean, numberno-repeat pool state.
start, freeze, reset() => voidPhase actions — start() is a no-op + fires onExhausted when the pool is empty.
resetHistory() => voidClears the noRepeat draw history without unmounting.
subscribe(fn: (value: number) => void) => () => voidTick subscription — for building fully custom renderers.

Exported types

typescript
PropTypeDefaultNotes
RafflePickValuenumber | stringValue type used across value, onSelect, initialValue, finalValue.
AnimationType'roll' | 'fade' | 'blur' | 'reel'Value animation kinds.
RafflePickPhase'idle' | 'starting' | 'running' | 'settling' | 'frozen'The phase state machine.
RaffleContextValueobjectReturn type of useRaffleContext() — everything above.

Full prop docs, recipes, and CSS custom properties live in the README on GitHub.