[
'https://picsum.photos/500/300?image=0',
'https://picsum.photos/500/300?image=44',
'https://picsum.photos/500/300?image=22'
];
import React, { Component } from 'react';
class Slider extends Component {
render() {
let currentSlideImage = 0;
return (
<div className="container">
<button onClick={this.handlePrevButton}>Prev</button>
<img src={this.props.slides[currentSlideImage]} alt="slider-item"/>
<button onClick={this.handleNextButton}>Next</button>
</div>
);
}
handlePrevButton = () => {
console.log('prev')
}
handleNextButton = () => {
currentSlideImage++;
}
}
export default Slider;
import React, { Component } from 'react';
class Slider extends Component {
constructor(props){
super()
this.state=({
currentSlideImage : 0
})
}
handlePrevButton(){
let currentSlideImage = this.state.currentSlideImage;
this.setState({
currentSlideImage:currentSlideImage-1
})
}
handleNextButton(){
let currentSlideImage = this.state.currentSlideImage;
this.setState({
currentSlideImage:currentSlideImage+1
})
}
render() {
return (
<div className="container">
<button onClick={()=>this.handlePrevButton()}>Prev</button>
<img src={this.props.slides[this.state.currentSlideImage]} alt="slider-item"/>
<button onClick={()=>this.handleNextButton()}>Next</button>
</div>
);
}
}
export default Slider;