Created
December 27, 2016 05:53
-
-
Save astrieanna/6d7a2a6e8c3b8ad195fb7c98e09e611b to your computer and use it in GitHub Desktop.
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
<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> |
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
div.card { | |
border: 1px solid green; | |
} |
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
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