WithStore: Cannot read property #39;state#39; of undefined (pure-react-carousel)(WithStore:无法读取未定义(纯-反应-旋转木马)的属性#39;状态#39;)
问题描述
我使用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:无法读取未定义(纯-反应-旋转木马)的属性';状态';的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:WithStore:无法读取未定义(纯-反应-旋转木马)的属性';状态';
基础教程推荐
- 在 contenteditable 中精确拖放 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
