Created
April 24, 2018 03:03
-
-
Save chongiscool/f2ebbaf26c42427a28713bb3f03a08a2 to your computer and use it in GitHub Desktop.
check out password and get contact info in ReactJS
This file contains hidden or 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 from 'react'; | |
import ReactDOM from 'react-dom'; | |
class Contact extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
password: 'swordfish', | |
authorized: false | |
}; | |
this.authorize = this.authorize.bind(this); | |
} | |
authorize(e) { | |
const password = e.target.querySelector( | |
'input[type="password"]').value; | |
const auth = password == this.state.password; | |
this.setState({ | |
authorized: auth | |
}); | |
} | |
render() { | |
const login = ( | |
<form action="#" onSubmit={this.authorize}> | |
<input type="password" placeholder="Password"/> | |
<input type="submit"/> | |
</form> | |
); | |
const contactInfo = ( | |
<ul> | |
<li> | |
[email protected] | |
</li> | |
<li> | |
555.555.5555 | |
</li> | |
</ul> | |
); | |
return ( | |
<div id="authorization"> | |
<h1> | |
{this.state.authorized ? 'Contact' : 'Enter the Password'} | |
</h1> | |
{this.state.authorized ? contactInfo : login} | |
</div> | |
); | |
} | |
} | |
ReactDOM.render( | |
<Contact />, | |
document.getElementById('app') | |
); | |
// code from codecademy.com project practice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment