Last active
August 16, 2018 15:15
-
-
Save h09shais/b56332fc133ad8c960b0fa3f746b0127 to your computer and use it in GitHub Desktop.
React Stateless Functional Component - Image Gallery
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 from "react"; | |
let Image = props => { | |
let source = props.source; | |
let style = { | |
margin: "10px 5px 0px 5px" | |
}; | |
return <img src={source} style={style} />; | |
}; | |
export default Image; |
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
// App.js | |
import React, { Component } from "react"; | |
import Images from "./images"; | |
class App extends Component { | |
state = { | |
images: [ | |
"https://loremflickr.com/320/240?random=1", | |
"https://loremflickr.com/320/240?random=2", | |
"https://loremflickr.com/320/240?random=3" | |
] | |
}; | |
render() { | |
return ( | |
<div className="App"> | |
<Images data={this.state.images} /> | |
</div> | |
); | |
} | |
} | |
export default App; |
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 from "react"; | |
import Image from "./image"; | |
let Images = props => { | |
return props.data.map(image => { | |
return <Image source={image} key={image} />; | |
}); | |
}; | |
export default Images; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment