React Spring Carousel

Types

If you're using typescript, you'll find that the library is fully typed out of the box. An important thing to keep in mind, however, is that you need to type the context to get the correct return types, based on the slide type you're using.

1
2  // import { useTransitionCarouselContext } from "react-spring-carousel";
3  import { useSpringCarouselContext } from "react-spring-carousel";
4
5  function Component() {
6    const { slideToPrevItem, slideToNextItem } = useSpringCarouselContext<"fluid" | "fixed">()
7
8    return (
9      <div>
10        Carousel item 1
11      </div>
12    )
13  }
14
The only difference in what is being returned depends on the slide type you're using in your carousel (some methods are not available when using the fluid slide type). Pass the correct slide type and you're done!