WithStore:无法读取未定义(纯-反应-旋转木马)的属性'状态' [英] WithStore: Cannot read property 'state' of undefined (pure-react-carousel)

查看:49
本文介绍了WithStore:无法读取未定义(纯-反应-旋转木马)的属性'状态'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用pure-react-carousel库,并尝试通过My Button的onClick方法导航到特定幻灯片。

请向我解释如何使用setStoreState,因为我试着自己做(就像文档中写的那样),并且我使用它的整个页面都是看不见的。我尝试使用this.props.carouselStore.setStoreState({ currentSlide: 2 })

当我使用Store添加导出时,我的页面变得不可见。并且我得到以下错误。

Error is Uncaught TypeError: Cannot read property 'state' of undefined
my export
    export default WithStore(MyComponent, state => ({
        currentSlide: state.currentSlide,
      }));

推荐答案

我实际上是Pure Reaction旋转木马的作者。

WithStore()仅当它是<CarouselProvider />的子级时才有效

WithStore访问Reaction的上下文API。CarouselProvider创建上下文。创建上下文时,Reaction仅将上下文向下传递给创建上下文的组件的子组件。

因此,在此伪代码示例中使用WithStore将显示错误。

<YourComponentThatUsesTheWithStoreHOC />
<CarouselProvider>
  // all your buttons, slides, dots, etc...
</CarouselProvider>

这也会使您出错。

<CarouselProvider>
  // all your buttons, slides, dots, etc...
</CarouselProvider>
<YourComponentThatUsesTheWithStoreHOC />

此伪代码示例将起作用

<CarouselProvider>
  // all your buttons, slides, dots, etc...
  <YourComponentThatUsesTheWithStoreHOC />
</CarouselProvider>

这篇关于WithStore:无法读取未定义(纯-反应-旋转木马)的属性&#39;状态&#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆