I'm trying to get the largePlayer in state to automatically change its values every 2 seconds, so I'm trying to use setTimeout to loop through the mediaRoll array (also in state), but I keep getting the error that "setState is not a function"
`import React from 'react';
import ReactDOM from 'react-dom';
import $ from 'jquery';
import Items from './Items.jsx';
import LargePlayer from './LargePlayer.jsx';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
largePlayer: "https://res.cloudinary.com/dq3iywusm/image/upload/w_600,h_337/1471163293-814525206_acfute.jpg",
mediaRoll: []
}
this.rotateMedia = this.rotateMedia.bind(this)
}
componentDidMount() {
this.loadMedia()
this.rotateMedia()
}
loadMedia() {
$.ajax({
method: 'GET',
url: '/media/items',
success: (data) => {
// console.log(data)
this.setState({
mediaRoll: JSON.parse(data)
})
this.rotateMedia()
},
error: (err) => {
console.log('error with ajax loadMedia: ', err)
}
})
}
rotateMedia() {
var array = this.state.mediaRoll
var interval = 2000;
array.forEach(function (el, index) {
setTimeout(function () {
this.setState({
largePlayer: el.url
})
console.log(el.url);
}, index * interval);
});
}
render() {
return (
<div >
<h1>Photo Carousel</h1>
<LargePlayer largePlayer={this.state.largePlayer} />
<Items mediaRoll={this.state.mediaRoll} />
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'));`
The ajax portion and everything works perfectly with the videos and pictures rendering, but I can't get that largePlayer in state to change every two seconds.