Skip to content

Instantly share code, notes, and snippets.

@andrewliebchen
Last active July 19, 2018 05:56
Show Gist options
  • Save andrewliebchen/52c8fac614efc3c2c3e7d474af232e2d to your computer and use it in GitHub Desktop.
Save andrewliebchen/52c8fac614efc3c2c3e7d474af232e2d to your computer and use it in GitHub Desktop.
Perhaps a way to simplify ResourceCards?
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;
@zachj0hnston
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment