Created
April 30, 2019 15:29
-
-
Save abhishekjakhar/38af10614c206c7e5ad397ea03f9f259 to your computer and use it in GitHub Desktop.
Returning Null - Initial State
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
import React, { Component } from 'react'; | |
import Mocktail from './Mocktail'; | |
class App extends Component { | |
state = { | |
mocktail: '' | |
} | |
updateMocktail = mocktail => this.setState({ mocktail }) | |
render() { | |
const mocktails = ['Cosmopolitan', 'Mojito', 'Blue Lagoon']; | |
return ( | |
<React.Fragment> | |
<header> | |
<h1>Select Your Mocktail</h1> | |
<nav> | |
{ | |
mocktails.map((mocktail) => { | |
return <button | |
key={mocktail} | |
value={mocktail} | |
type="button" | |
onClick={e => this.updateMocktail(e.target.value)}>{mocktail}</button> | |
}) | |
} | |
</nav> | |
</header> | |
<main> | |
<Mocktail mocktail={this.state.mocktail} /> | |
</main> | |
</React.Fragment> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment