I want to use Owl Carousel with React, and I am new to React.
Please see this jsfiddle, I spent much time to do it.
The JSX code
var Carousel = React.createClass({
componentDidMount: function(){
$(React.findDOMNode(this)).owlCarousel({
items: 4
});
},
render: function(){
return(
<div id="inx-carousel-thumb" className="owl-carousel">
{
this.props.images.map(function(image, index){
return (
<div className="item" key={index}><img src={image} /></div>
)
}.bind(this))
}
</div>
);
}
});
var imagesList = [['http://www.myfacewhen.net/uploads/3908-troll-smile.jpg', 'http://www.captionite.com/templates/thumb-success.jpg', 'http://pauljadam.com/forma11y/img/rage-guy-teeth-smile.jpg'],['http://i2.kym-cdn.com/entries/icons/original/000/004/073/smile.png']];
var Container = React.createClass({
getInitialState: function(){
return {
images: imagesList[0]
};
},
changeImages: function(index) {
this.setState({images: imagesList[index]});
},
render: function(){
return(
<div>
<Carousel images={this.state.images} />
<input type="button" onClick={this.changeImages.bind(this, 0)} value="Images List 0" />
<input type="button" onClick={this.changeImages.bind(this, 1)} value="Images List 1" />
</div>
);
}
});
$(document).ready(function(){
React.render(
<Container />,
document.getElementById('container')
);
});
I included Jquery, Reactjs, Owl Carousel, too.
The problem is that when I tap button "Images List 1" to change the source array of Owl Carousel, the item count of carousel should become 1. However, it is still 3, and it only change first item. I think React only replace first item and ignore whole div, but I don't know how to fix it. Please give me some hints.