From c75b3700283dafaf73bca9b8d89916e6aa2088a6 Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Sun, 6 Sep 2020 14:24:23 +0300 Subject: [PATCH] Update Carousel --- snippets/Carousel.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/snippets/Carousel.md b/snippets/Carousel.md index f9c585090..6be833ddf 100644 --- a/snippets/Carousel.md +++ b/snippets/Carousel.md @@ -12,7 +12,7 @@ Renders a carousel component. - Render the carousel items using `React.cloneElement()` and pass down rest `props` along with the computed styles. ```jsx -function Carousel(props) { +const Carousel = ({ carouselItems, ...rest }) => { const [active, setActive] = React.useState(0); let scrollInterval = null; const style = { @@ -29,12 +29,11 @@ function Carousel(props) { }; React.useEffect(() => { scrollInterval = setTimeout(() => { - const { carouselItems } = props; setActive((active + 1) % carouselItems.length); }, 2000); return () => clearTimeout(scrollInterval); }); - const { carouselItems, ...rest } = props; + return (
{carouselItems.map((item, index) => { @@ -49,7 +48,7 @@ function Carousel(props) { })}
); -} +}; ``` ```jsx