useRiffleState()
useRiffleState<
T>(riffle,selector):T
Defined in: react/useRiffleState.ts:21
Subscribe to one slice of the snapshot. A component selecting activeIndex
does not re-render when isDragging flips. The selected value is cached per
snapshot, so a selector that returns a new object is safe.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”riffle
Section titled “riffle”selector
Section titled “selector”(snapshot) => T
Returns
Section titled “Returns”T
Example
Section titled “Example”import { useRiffle, useRiffleState } from '@rpxl/riffle/react'
function Stack({ films }: { films: { title: string }[] }) { const riffle = useRiffle({ count: films.length }) const activeIndex = useRiffleState(riffle, (snapshot) => snapshot.activeIndex) return <p>{films[activeIndex]?.title}</p>}