gpt4 book ai didi

javascript - 未捕获的类型错误 : cannot read property persist of undefined with react-bootstrap carousel

转载 作者:搜寻专家 更新时间:2023-11-01 04:35:37 25 4
gpt4 key购买 nike

我正在实现 react-bootsrap带有 react-redux 的旋转木马,我在标题中收到错误。

我正在使用受控轮播,当轮播自动更换幻灯片时出现错误消息。

当用户点击上一个。下一个按钮并手动更改它似乎没问题。

我不明白我应该将 persist 作为 props 或 options 添加到 props 或类似的东西吗?

这是我的代码:

容器:

import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router'
import store from 'store/configureStore'
import Slides from 'components/SlideShow'
import { getInitalSlides, handleSelect } from 'actions/SlidesActions'

class Home extends Component {

constructor(props) {
super(props)
this.state = {
index: null,
direction: null
}
this.handleSelect = this.handleSelect.bind(this)

static fetchData({ store }) {
return store.dispatch(getInitalSlides())
}

componentDidMount() {
this.props.getInitalSlides()
}

handleSelect(selectedIndex, e) {
//alert(e)
this.props.handleSelect(selectedIndex, e)
}

render() {
return (
<div className="Home">
<h1>Home Page</h1>
<Slides
slides={this.props.slides}
getInitialState={this.state.index}
getInitialStateD={this.state.direction}
slidesControl={this.handleSelect}
/>
<div><Link to="/question">to question</Link></div>
<div><Link to="/posts">to posts</Link></div>
</div>
)
}
}

function mapStateToProps (state) {
const { slides, handleSelect } = state

return { slides: state.slides, onSelect: state.handleSelect }
}

export { Home }
export default connect(mapStateToProps { getInitalSlides, handleSelect})(Home)

这是组件中的相关位:

    render() {

return (
<Carousel
activeIndex={this.props.getInitialState}
direction={this.props.getInitialStateD}
onSelect={(selectedIndex,e)=>this.props.slidesControl(selectedIndex,e)}
>
{

this.props.slides.map((s)=>{
let id = s.get('id')
let title = s.get('title')
let image = s.get('image')
let alt = s.get('alt')
let caption = s.get('caption')
return(

<Carousel.Item key={id} >
<img width={900} height={500} alt={s.get('alt')} src={image} alt={alt}/>
<Carousel.Caption>
<h3>{title}</h3>
<p>{caption}</p>
</Carousel.Caption>
</Carousel.Item>

)
})



}
</Carousel>)
}
}

编辑:这里是相关的react-bootstrap轮播代码(报错的地方)

  var onSelect = this.props.onSelect;

if (onSelect) {
if (onSelect.length > 1) {
// React SyntheticEvents are pooled, so we need to remove this event
// from the pool to add a custom property. To avoid unnecessarily
// removing objects from the pool, only do this when the listener
// actually wants the event.
e.persist();
e.direction = direction;

onSelect(index, e);
} else {
onSelect(index);
}
}

最佳答案

我分析了 react-bootstrapCarousel.js 代码,我怀疑它是 react-bootstrap 库本身的问题。

There is this line triggering change in Carousel.js code :

this.timeout = setTimeout(this.next, this.props.interval);

this.next 方法需要 SynteticEvent 类型的参数,但 setTimeout 调用没有传递任何参数。这 exlpains 您的错误消息:...persist of undefined...

这个问题可能隐藏了很长时间,but was exposed with this commit ,其中事件参数实际由 Carousel.ja 代码本身使用。

所以我建议创建 react-bootstrap Github 问题,同时降级到不包含上述提交的版本。

关于javascript - 未捕获的类型错误 : cannot read property persist of undefined with react-bootstrap carousel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38222883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com