跳至主要内容

手動控制

手動控制導航項目控制器 Controller

如果你想要在API資料取回時自動跳到指定頁 slideToPage,請將 isUseAnimation 參數帶 false

import BearCarousel, {Controller,ICarouselState} from 'bear-react-carousel';
import {useState,useEffect} from 'react';

const SyncCarousel = () => {
const [controller, setController] = useState<Controller>();
const [carouselState, setCarouselState] = useState<ICarouselState>();

useEffect(() => {
handleSlide(4, false);

}, [controller]);

const handleSlide = (page: number, isUseAnimation = true) => {
controller?.slideToPage(page, isUseAnimation);
}

return <div>
<BearCarousel
// ...ignore some
onSlideChange={setCarouselState}
setController={setController}
/>

currentPage: {GridState?.page.total}
</div>
}

試試看點擊 Page1 ~ Page6 按鈕