Skip to content

Instantly share code, notes, and snippets.

@codingnninja
Created March 11, 2019 13:07
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 codingnninja/3e47b74d7ac9cb288c965966ef0bd549 to your computer and use it in GitHub Desktop.
Save codingnninja/3e47b74d7ac9cb288c965966ef0bd549 to your computer and use it in GitHub Desktop.
Login (A class component)
class Login extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleLogIn = this.handleLogIn.bind(this);
this.state = {username: ''};
}
render() {
return (
<Dialog title="Login now"
message="Get more superpowers for free">
<input value={this.state.username}
onChange={this.handleChange} />
<button onClick={this.handleLogIn}>
Log Me In!
</button>
</Dialog>
);
}
handleChange(e) {
this.setState({username: e.target.value});
}
handleLogIn() {
alert(`Welcome back, ${this.state.username}!`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment