Skip to content

Instantly share code, notes, and snippets.

@ldco2016
Last active September 26, 2019 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldco2016/1cb6331ea4f79cb8a6319dea0155ca03 to your computer and use it in GitHub Desktop.
Save ldco2016/1cb6331ea4f79cb8a6319dea0155ca03 to your computer and use it in GitHub Desktop.
file to be worked on
import React, { Component } from "react";
import { reduxForm, Field } from "redux-form";
class Signup extends Component {
// bonus
// by making method below an arrow function
// developer does not have to worry
// about binding the context of onSubmit
// saves having to call bind(this) somewhere
// as first argument, all properties user entered into form - an object with email, password
onSubmit = formProps => {
// candidate should display logging formProps to ensure they are indeed getting
// correct data entered in form by user
console.log(formProps);
};
render() {
// the candidate would understand that the email and Password
// would have to be taken out of the form itself and provided to
// onSubmit callback via handleSubmit property provided by reduxForm.
const { handleSubmit } = this.props;
return (
// to handleSubmit() the callback is passed with no parens because
// we are not calling onSubmit the instance the form is rendered
// we are only passing a reference to onSubmit, not a call.
<form onSubmit={handleSubmit(this.onSubmit)}>
<fieldset>
<label>Email</label>
<Field
name="email"
type="text"
component="input"
autoComplete="none"
/>
</fieldset>
<fieldset>
<label>Password</label>
<Field
name="password"
type="password"
component="input"
autoComplete="none"
/>
</fieldset>
<button>Sign Up!</button>
</form>
);
}
}
export default reduxForm({ form: "signup" })(Signup);
// candidate will then add email and password, totally arbitrary and the idea is
// to be able to see those credentials logged in console.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment