Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. import React, { useState } from 'react';
  2. import axios from 'axios';
  3.  
  4. function Register() {
  5.  
  6. const [password, setPassword] = useState('');
  7. const [retypePassword, setRetypePassword] = useState('');
  8. const [lastName, setLastName] = useState('');
  9. const [firstName, setFirstName] = useState('');
  10. const [address, setAddress] = useState('');
  11. const [email, setEmail] = useState('');
  12.  
  13. const handleRegister = () => {
  14. axios.post('http://localhost:8000/users', {
  15. password: password,
  16. lastName: lastName,
  17. firstName: firstName,
  18. address: address,
  19. email: email
  20. })
  21. .then((result) => {
  22. console.log(result.data);
  23. })
  24. }
  25.  
  26. return (
  27. <div className="mt-5">
  28. <div class="form-row">
  29. <div class="form-group col-md-6">
  30. <label for="inputFirstName4">FirstName</label>
  31. <input type="text" value={firstName} onChange={(event) => setFirstName(event.target.value)} class="form-control" id="inputFirstName4" placeholder="FirstName" />
  32. </div>
  33. </div>
  34. <div class="form-row">
  35. <div class="form-group col-md-6">
  36. <label for="inputLastName4">LastName</label>
  37. <input type="text" value={lastName} onChange={(event) => setLastName(event.target.value)} class="form-control" id="inputLastName4" placeholder="LastName" />
  38. </div>
  39. </div>
  40. <div class="form-row">
  41. <div class="form-group col-md-6">
  42. <label for="inputEmail4">Email</label>
  43. <input type="email" value={email} onChange={(event) => setEmail(event.target.value)} class="form-control" id="inputEmail4" placeholder="Email" />
  44. </div>
  45. </div>
  46. <div class="form-row">
  47. <div class="form-group col-md-6">
  48. <label for="inputPassword4">Password</label>
  49. <input type="password" value={password} onChange={(event) => setPassword(event.target.value)} class="form-control" id="inputPassword4" placeholder="Password" />
  50. </div>
  51. <div class="form-group col-md-6">
  52. <label for="inputPassword4">Retype password</label>
  53. <input type="password" value={retypePassword} onChange={(event) => setRetypePassword(event.target.value)} class="form-control" id="inputPassword4" placeholder="Password" />
  54. </div>
  55. {password !== retypePassword && <p className="text-danger">Password not equal</p>}
  56. </div>
  57. <div class="form-group">
  58. <label for="inputAddress">Address</label>
  59. <input type="text" value={address} onChange={(event) => setAddress(event.target.value)} class="form-control" id="inputAddress" placeholder="" />
  60. </div>
  61. <button class="btn btn-primary" onClick={handleRegister}>Sign in</button>
  62. </div>
  63. )
  64. }
  65.  
  66. export default Register;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement