Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3.  
  4. class Contact extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. password: 'swordfish',
  9. authorized: false
  10. };
  11. this.authorize = this.authorize.bind(this);
  12. }
  13.  
  14. authorize(e) {
  15. const password = e.target.querySelector(
  16. 'input[type="password"]').value;
  17. const auth = password == this.state.password;
  18. this.setState({
  19. authorized: auth
  20. });
  21. }
  22.  
  23. render() {
  24. let title;
  25.  
  26. if (this.state.authorized) {
  27. title = 'Contact';
  28. } else {
  29. title = 'Enter the Password';
  30. }
  31.  
  32. const login = (
  33. <form action="#" onSubmit={this.authorize}>
  34. <input type="password"/>
  35. <input type="submit"/>
  36. </form>
  37. );
  38.  
  39. const contactInfo = (
  40. <ul>
  41. <li>
  42. client@example.com
  43. </li>
  44. <li>
  45. 555.555.5555
  46. </li>
  47. </ul>
  48. );
  49.  
  50. return (
  51. <div id="authorization">
  52. <h1>{title}</h1>
  53. {this.state.authorized ? contactInfo : login}
  54. </div>
  55. );
  56. }
  57. }
  58.  
  59. ReactDOM.render(
  60. <Contact />,
  61. document.getElementById('app')
  62. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement