I'm implementing a react-bootsrap carousel with react-redux and I'm getting the error in the title.
I'm using a controlled carousel and the error message appears when the carousel changes a slide automatically.
When the user clicks prev. next buttons and changes it manually all seems to be ok.
I don't get it should I add persist as props or options to props or similar?
Here's my code:
container:
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)
and here is the relevant bit in the component:
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>)
}
}
Edit: Here is the relevant react-bootstrap carousel code (where the error is thrown)
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);
}
}
I analyzed Carousel.js
code of react-bootstrap
and I suspect it is issue in react-bootstrap
library itself.
There is this line triggering change in Carousel.js code:
this.timeout = setTimeout(this.next, this.props.interval);
this.next
method expects parameter of type SynteticEvent
, but none is passed from setTimeout
call. That exlpains your error message: ...persist of undefined...
.
The issue was probably hidden for a long time, but was exposed with this commit, where event parameter is actually used by Carousel.ja code itself.
So I recommend to create react-bootstrap Github issue and in the meantime downgrade to version that doesn't contain mentioned commit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With