Skip to content

Instantly share code, notes, and snippets.

@abhishekjakhar
Created April 30, 2019 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhishekjakhar/38af10614c206c7e5ad397ea03f9f259 to your computer and use it in GitHub Desktop.
Save abhishekjakhar/38af10614c206c7e5ad397ea03f9f259 to your computer and use it in GitHub Desktop.
Returning Null - Initial State
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