import React, { Component } from 'react';
import Slider from './Slider';
import slides from './slides';
class App extends Component {
render() {
return (
<Slider slides={slides}/>
);
}
}
export default App;
import React, { Component } from 'react';
class Slider extends Component {
constructor(props){
super()
this.state=({
currentSlideImage : 0
})
}
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>
);
}
handlePrevButton = () => {
console.log('--')
}
handleNextButton = () => {
let currentSlideImage = this.state.currentSlideImage;
this.setState({
currentSlideImage:currentSlideImage++
})
console.log(this.state.currentSlideImage);
console.log(this.state);
console.log(this.props);
}
}
export default Slider;
export default [
'https://picsum.photos/500/300?image=0',
'https://picsum.photos/500/300?image=44',
'https://picsum.photos/500/300?image=22',
'https://picsum.photos/500/300?image=33',
'https://picsum.photos/500/300?image=4',
'https://picsum.photos/500/300?image=55',
'https://picsum.photos/500/300?image=66'
];
console.log(this.state.currentSlideImage);