` around the surrounding container. The `
` holds the directional and sliding state, and within that container the items we want to display are mapped as `React.Children`, utilizing `getOrder`.
+
+When we put it all together, our `` is complete!
+
+```typescript
+const Carousel: FunctionComponent<{children: ReactNode}> = (props) => {
+ const numItems = React.Children.count(props.children);
+ const [state, dispatch] = React.useReducer(reducer, getInitialState(numItems));
+
+ const slide = (dir: Direction) => {
+ dispatch({ type: dir, numItems });
+ setTimeout(() => {
+ dispatch({ type: 'stopSliding' });
+ }, 50);
+ };
+
+ const handlers = useSwipeable({
+ onSwipedLeft: () => slide(NEXT),
+ onSwipedRight: () => slide(PREV),
+ swipeDuration: 500,
+ preventScrollOnSwipe: true,
+ trackMouse: true
+ });
+
+ return (
+
+
+
+ {React.Children.map(props.children, (child, index) => (
+
+ {child}
+
+ ))}
+
+
+
+ slide(PREV)} float="left">
+ Prev
+
+ slide(NEXT)} float="right">
+ Next
+
+
+
+ );
+};
+```
diff --git a/docs/src/components/examples/SimpleCarousel/index.tsx b/docs/src/components/examples/SimpleCarousel/index.tsx
index 105d12ea..28283fcd 100644
--- a/docs/src/components/examples/SimpleCarousel/index.tsx
+++ b/docs/src/components/examples/SimpleCarousel/index.tsx
@@ -16,15 +16,6 @@ function SimpleCarousel() {
- Note: swipe must be "faster" than 500ms to trigger.
-
-
- See code
- {" "}
- for example usage of{" "}
- swipeDuration
and{" "}
- preventScrollOnSwipe
.
-
);
}
diff --git a/examples/app/SimpleCarousel/index.tsx b/examples/app/SimpleCarousel/index.tsx
index 4b61ef15..546dfe3c 100644
--- a/examples/app/SimpleCarousel/index.tsx
+++ b/examples/app/SimpleCarousel/index.tsx
@@ -7,10 +7,6 @@ import Carousel from './Carousel';
function SimpleCarousel() {
return (