Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
div.card {
border: 1px solid green;
}
var myhand = ["3hearts", "2spades", "Dragon"]
var Card = React.createClass({
render: function() {
return <div className="card"> {
this.props.contents
} <button onClick={this.props.onC}>Play</button></div>;
}
});
var MyHand = React.createClass({
getInitialState: function() {
return {
cards: this.props.cards.splice(0)
}
},
playCard: function(card) {
this.state.cards.splice(this.state.cards.indexOf(card),1);
this.setState({cards: this.state.cards})
},
render: function() {
var that = this
return ( < div > {
this.state.cards.map(function(card) {
return ( < Card contents={card} onC={that.playCard.bind(null, card)}/>)
})
} < /div>)}
});
ReactDOM.render( < MyHand cards={myhand}/ > ,
document.getElementById('container')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment