Last active
July 19, 2018 05:56
-
-
Save andrewliebchen/52c8fac614efc3c2c3e7d474af232e2d to your computer and use it in GitHub Desktop.
Perhaps a way to simplify ResourceCards?
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 './App.css'; | |
const cards = ['Card 1', 'Card 2', 'Card 3']; | |
const Card = props => ( | |
<div | |
onClick={props.handleClick} | |
className="Card" | |
style={{transform: props.selected && 'scale(1.5)'}}> | |
<div>{props.children}</div> | |
</div> | |
); | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
selected: null, | |
}; | |
} | |
render() { | |
return ( | |
<div className="App"> | |
{cards.map(card => ( | |
<Card | |
key={card} | |
selected={this.state.selected === card} | |
handleClick={() => this.setState({selected: card})}> | |
{card} | |
</Card> | |
))} | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I finally looked up what .map() is in javascript. I see it everywhere in React and didn't realize it's basically a .forEach() loop that returns an array. Neat :)