Created
February 15, 2018 19:41
-
-
Save g-patel/49a29e9a8728589e0a704a3919bf0a04 to your computer and use it in GitHub Desktop.
index.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
<!DOCTYPE html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<div id="root">nothing rendered yet</div> | |
<script src='https://unpkg.com/[email protected]/umd/react.development.js'></script> | |
<script src='https://unpkg.com/[email protected]/umd/react-dom.development.js'></script> | |
<script src="https://unpkg.com/@babel/[email protected]/babel.js"></script> | |
<script type="text/babel"> | |
const favCities = [ | |
'San Francisco', | |
'New York', | |
'Vegas' | |
]; | |
class FavoriteCity extends React.Component { | |
constructor (props) { | |
super(props); | |
this.state = { | |
fontWeight: 'bold' | |
} | |
this.toggleFontWeight = this.toggleFontWeight.bind(this); | |
} | |
toggleFontWeight() { | |
const newFontWeight = this.state.fontWeight === 'bold' ? 'normal' : 'bold'; | |
this.setState({fontWeight: newFontWeight}); | |
} | |
render() { | |
return ( | |
<li | |
style={ | |
{ | |
fontWeight: this.state.fontWeight, | |
color: 'limegreen' | |
} | |
} | |
onClick={this.toggleFontWeight}>{this.props.city} | |
</li> | |
); | |
} | |
}; | |
// const FavoriteCity = function (props) { | |
// return ( | |
// React.createElement('li', {style: {color: 'limegreen'}}, props.city) | |
// ); | |
// }; | |
const App = () => { | |
return ( | |
<div id="cities"> | |
<h1>My Fav Cities</h1> | |
<ul> | |
{ | |
favCities.map(function (city) { | |
return ( | |
<FavoriteCity city={city} /> | |
) | |
}) | |
} | |
</ul> | |
</div> | |
) | |
} | |
ReactDOM.render(<App />, document.getElementById('root')); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment