代码之家  ›  专栏  ›  技术社区  ›  Marion

有没有办法通过自动播放来定制另一个react灯箱转盘?

  •  0
  • Marion  · 技术社区  · 1 年前

    我正在使用next@13并尝试使另一个react灯箱(v3.12.2)的内联转盘每隔几秒钟导航一次。

    这是我尝试过的:

    'use client';
    
    import Lightbox, { useController } from 'yet-another-react-lightbox';
    import Inline from 'yet-another-react-lightbox/plugins/inline';
    
    export default function MyComponent ({ slides }: Props) {
      const { next } = useController();
    
      useEffect(() => {
          setTimeout(function () {
            next();
          }, 3000);
        });
    
        return (
          <Lightbox
            slides={slides}
            plugins={[Inline]}
            inline={{
              style: {...},
            }}
            carousel={{...}}
          />
        );
    }
    

    但它不起作用,我得到了这个错误:

    Error: useController must be used within a ControllerContext.Provider

    我看不出里面有这个useController()钩子的上下文是什么。也许这是一个需要做的“道具增强”,但我不太了解有关它的文档。有人知道吗? 谢谢

    0 回复  |  直到 1 年前