Last active
September 21, 2018 15:20
-
-
Save stecrv/5e5d07bcfe050a2b9f2652cd43b7cddd 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://unpkg.com/@babel/standalone/babel.js"></script> | |
<script src="https://unpkg.com/react/umd/react.development.js"></script> | |
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script> | |
</head> | |
<div id="root"></div> | |
<script type="text/babel"> | |
const NowEating = props => <h1>{props.meal}</h1> | |
class Menu extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
meal: "food" | |
} | |
this.addSideDish =this.addSideDish.bind(this); | |
} | |
addSideDish = () => { | |
this.setState(prevState => { | |
return { meal: `${prevState.meal} Changed`} | |
}) | |
} | |
render() { | |
return ( | |
<div> | |
<NowEating meal={this.state.meal} /> | |
{(this.state.meal === "food") | |
? <button onClick={this.addSideDish}>Click to change</button> | |
: null | |
} | |
</div> | |
) | |
} | |
} | |
ReactDOM.render( | |
<Menu />, | |
document.getElementById('root') | |
) | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment