Created
July 27, 2018 07:05
-
-
Save sineau/1326eada231a17d4cf10c8e1ced9b40b to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/fahewaz
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://fb.me/react-15.1.0.js"></script> | |
<script src="https://fb.me/react-dom-15.1.0.js"></script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id='container'></div> | |
<script id="jsbin-javascript"> | |
function CounterPresenter(props) { | |
return( | |
React.createElement("div", null, | |
React.createElement("p", null, props.counter), | |
React.createElement("button", {type: "button", onClick: props.onIncrement}, "Increase"), | |
React.createElement("button", {type: "button", onClick: props.onDecrement}, "Decrease") | |
) | |
) | |
} | |
class Counter extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
counter: 0 | |
} | |
this.onIncrement = this.onIncrement.bind(this) | |
this.onDecrement = this.onDecrement.bind(this) | |
} | |
onIncrement() { | |
this.setState({ | |
counter: this.state.counter + 1 | |
}) | |
} | |
onDecrement() { | |
this.setState({ | |
counter: this.state.counter - 1 | |
}) | |
} | |
render() { | |
return( | |
React.createElement(CounterPresenter, { | |
counter: this.state.counter, | |
onIncrement: this.onIncrement, | |
onDecrement: this.onDecrement}) | |
) | |
} | |
} | |
ReactDOM.render( | |
React.createElement(Counter, null), | |
document.getElementById('container') | |
); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function CounterPresenter(props) { | |
return( | |
<div> | |
<p>{props.counter}</p> | |
<button type="button" onClick={props.onIncrement}>Increase</button> | |
<button type="button" onClick={props.onDecrement}>Decrease</button> | |
</div> | |
) | |
} | |
class Counter extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
counter: 0 | |
} | |
this.onIncrement = this.onIncrement.bind(this) | |
this.onDecrement = this.onDecrement.bind(this) | |
} | |
onIncrement() { | |
this.setState({ | |
counter: this.state.counter + 1 | |
}) | |
} | |
onDecrement() { | |
this.setState({ | |
counter: this.state.counter - 1 | |
}) | |
} | |
render() { | |
return( | |
<CounterPresenter | |
counter={this.state.counter} | |
onIncrement={this.onIncrement} | |
onDecrement={this.onDecrement} /> | |
) | |
} | |
} | |
ReactDOM.render( | |
<Counter />, | |
document.getElementById('container') | |
);</script></body> | |
</html> |
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
function CounterPresenter(props) { | |
return( | |
React.createElement("div", null, | |
React.createElement("p", null, props.counter), | |
React.createElement("button", {type: "button", onClick: props.onIncrement}, "Increase"), | |
React.createElement("button", {type: "button", onClick: props.onDecrement}, "Decrease") | |
) | |
) | |
} | |
class Counter extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
counter: 0 | |
} | |
this.onIncrement = this.onIncrement.bind(this) | |
this.onDecrement = this.onDecrement.bind(this) | |
} | |
onIncrement() { | |
this.setState({ | |
counter: this.state.counter + 1 | |
}) | |
} | |
onDecrement() { | |
this.setState({ | |
counter: this.state.counter - 1 | |
}) | |
} | |
render() { | |
return( | |
React.createElement(CounterPresenter, { | |
counter: this.state.counter, | |
onIncrement: this.onIncrement, | |
onDecrement: this.onDecrement}) | |
) | |
} | |
} | |
ReactDOM.render( | |
React.createElement(Counter, null), | |
document.getElementById('container') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment