Skip to content

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.

T

RiffleHandle

(snapshot) => T

T

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>
}