Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import { reduxForm, Field } from "redux-form";
  3.  
  4. class Signup extends Component {
  5. // bonus
  6. // by making method below an arrow function
  7. // developer does not have to worry
  8. // about binding the context of onSubmit
  9. // saves having to call bind(this) somewhere
  10.  
  11. // as first argument, all properties user entered into form - an object with email, password
  12. onSubmit = formProps => {
  13. // candidate should display logging formProps to ensure they are indeed getting
  14. // correct data entered in form by user
  15. console.log(formProps);
  16. };
  17.  
  18. render() {
  19. // the candidate would understand that the email and Password
  20. // would have to be taken out of the form itself and provided to
  21. // onSubmit callback via handleSubmit property provided by reduxForm.
  22. const { handleSubmit } = this.props;
  23. return (
  24. // to handleSubmit() the callback is passed with no parens because
  25. // we are not calling onSubmit the instance the form is rendered
  26. // we are only passing a reference to onSubmit, not a call.
  27. <form onSubmit={handleSubmit(this.onSubmit)}>
  28. <fieldset>
  29. <label>Email</label>
  30. <Field
  31. name="email"
  32. type="text"
  33. component="input"
  34. autoComplete="none"
  35. />
  36. </fieldset>
  37. <fieldset>
  38. <label>Password</label>
  39. <Field
  40. name="password"
  41. type="password"
  42. component="input"
  43. autoComplete="none"
  44. />
  45. </fieldset>
  46. <button>Sign Up!</button>
  47. </form>
  48. );
  49. }
  50. }
  51.  
  52. export default reduxForm({ form: "signup" })(Signup);
  53.  
  54. // candidate will then add email and password, totally arbitrary and the idea is
  55. // to be able to see those credentials logged in console.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement