@neynar/ui
Version:
React UI component library built on shadcn/ui and Tailwind CSS
55 lines (41 loc) • 1.25 kB
Markdown
and controls Must be used within a Carousel component. Provides access to the carousel API and navigation methods for building custom carousel interactions.
```typescript
import { useCarousel } from '@neynar/ui';
export function useCarousel(): ReturnType<typeof useCarousel> { ... }
```
**Return Type**: `ReturnType<typeof useCarousel>`
**Description**: Carousel context containing API, navigation controls, and state
```typescript
import { useCarousel } from '@neynar/ui';
const result = useCarousel();
```
```tsx
function CarouselDots() {
const { api, scrollNext, canScrollNext } = useCarousel();
const [current, setCurrent] = useState(0);
useEffect(() => {
if (!api) return;
setCurrent(api.selectedScrollSnap());
api.on('select', () => setCurrent(api.selectedScrollSnap()));
}, [api]);
return (
<div className="flex gap-2">
{Array.from({ length: 5 }).map((_, i) => (
<button
key={i}
className={current === i ? "active" : ""}
onClick={() => api?.scrollTo(i)}
/>
))}
</div>
);
}
```
- Error when used outside of Carousel component
**Type**: hook
Hook to access carousel context