Skip to content

Instantly share code, notes, and snippets.

@lucianoschillagi
Last active December 19, 2018 02:05
Show Gist options
  • Save lucianoschillagi/24d6449ae4c1f757e647e8e5d4da4e0a to your computer and use it in GitHub Desktop.
Save lucianoschillagi/24d6449ae4c1f757e647e8e5d4da4e0a to your computer and use it in GitHub Desktop.
// Authorization Form
import React from 'react';
import ReactDOM from 'react-dom';
class Contact extends React.Component {
// constructor method
constructor(props) {
super(props);
this.state = {
password: 'swordfish',
authorized: false
};
this.authorize = this.authorize.bind(this);
}
// authorize method
authorize(e) {
const password = e.target.querySelector(
'input[type="password"]').value;
const auth = password == this.state.password;
this.setState({
authorized: auth
});
}
// render method
render() {
// login variable
const login = (
<form action="#" onSubmit={this.authorize}>
<input
type="password"
placeholder="Password" />
<input type="submit" />
</form>
);
// contact info variable
const contactInfo = (
<ul>
<li>
[email protected]
</li>
<li>
555.555.5555
</li>
</ul>
);
// return statement
return (
<div id="authorization">
<h1>
{ this.state.authorized ? 'Contact' : 'Enter the Password' }
</h1>
{ this.state.authorized ? contactInfo : login }
<ul>
<li>
[email protected]
</li>
<li>
555.555.5555
</li>
</ul>
</div>
);
}
}
ReactDOM.render(
<Contact />,
document.getElementById('app')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment