import { ReactNode } from 'react' import { NoInfer, Falsy } from '@react-spring/types' import { is } from '@react-spring/shared' import { Valid } from '../types/common' import { PickAnimated, SpringValues } from '../types' import { UseSpringProps } from '../hooks/useSpring' import { useTrail } from '../hooks/useTrail' export type TrailComponentProps = unknown & UseSpringProps & { items: readonly Item[] children: ( item: NoInfer, index: number ) => ((values: SpringValues>) => ReactNode) | Falsy } export function Trail>({ items, children, ...props }: Props & Valid>) { const trails: any[] = useTrail(items.length, props) return items.map((item, index) => { const result = children(item, index) return is.fun(result) ? result(trails[index]) : result }) }