A Pen by Olivier Duhart on CodePen.
Created
January 16, 2019 08:03
-
-
Save b3b00/5bb3f14449de6bfd3bf9db1c0d20e48d to your computer and use it in GitHub Desktop.
react - class
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 id="root"></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
class Composant extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
message : "Hello" | |
}; | |
this.onClickGoodBye = this.onClickGoodBye.bind(this); | |
} | |
render() { | |
return ( | |
<div> | |
<h1>{this.state.message} {this.props.toto} !</h1> | |
<button type="button" class="btn btn-dark btn-block" onClick={this.onClickGoodBye}>toggle</button> | |
</div>); | |
} | |
onClickGoodBye = event => { | |
//alert("current state = >"+this.state.message+"<") | |
var newMessage = "Bye" | |
switch(this.state.message) { | |
case "Bye" : { | |
newMessage = "Hello" | |
break; | |
} | |
case "Hello" : { | |
newMessage ="Bye" | |
} | |
} | |
this.setState({message : newMessage}); | |
}; | |
} | |
ReactDOM.render( | |
<Composant toto="bidule"/>, document.getElementById('root') | |
); |
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://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script> |
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
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment