Last active
October 4, 2018 11:19
-
-
Save DZuz14/d104a4303e3745eb9f390e3ea45f7d11 to your computer and use it in GitHub Desktop.
Mapping Over Images in Slider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import Slide from '../slide' | |
import LeftArrow from '../left-arrow' | |
import RightArrow from '../right-arrow' | |
export default class Slider extends Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
images: [ | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/aurora.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/canyon.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/city.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/desert.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/mountains.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/redsky.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/sandy-shores.jpg", | |
"https://s3.us-east-2.amazonaws.com/dzuz14/thumbnails/tree-of-life.jpg" | |
], | |
currentIndex: 0 | |
} | |
} | |
goToPrevSlide = () => { | |
} | |
goToNextSlide = () => { | |
this.setState(prevState => ({ | |
currentIndex: prevState.currentIndex + 1 | |
})); | |
} | |
render() { | |
return ( | |
<div className="slider"> | |
{ | |
this.state.images.map((image, i) => ( | |
<Slide key={i} image={image} /> | |
)) | |
} | |
<LeftArrow | |
goToPrevSlide={this.goToPrevSlide} | |
/> | |
<RightArrow | |
goToNextSlide={this.goToNextSlide} | |
/> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment