Skip to content

Instantly share code, notes, and snippets.

@davidnguyen11
Last active December 6, 2018 16:24
Show Gist options
  • Save davidnguyen11/7353445a1fac97f71931cede2111f8f1 to your computer and use it in GitHub Desktop.
Save davidnguyen11/7353445a1fac97f71931cede2111f8f1 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { Field, initialize } from 'redux-form';

import withForm from 'withForm';

const FORM_NAME = 'registerForm';
const Form = withForm(FORM_NAME);

class Filter extends Component {
  handleSubmit = values => {
    console.log('filter', values);
  }

  render() {
    return (
      <Form onSubmit={this.handleSubmit}> 
         <div>
          <label htmlFor="firstName">First Name</label>
          <Field name="firstName" component="input" type="text" />
        </div>
        <div>
          <label htmlFor="lastName">Last Name</label>
          <Field name="lastName" component="input" type="text" />
        </div>
        <div>
          <label htmlFor="email">Email</label>
          <Field name="email" component="input" type="email" />
        </div>
        <button type="submit">Submit</button>
      </Form>
    );
  }
}

export default Filter;
import React from 'react';
import PropTypes from 'prop-types';
import { reduxForm } from 'redux-form';
function withForm(formName) {
function FormWrapper(props) {
const { handleSubmit } = props;
return (
<form onSubmit={handleSubmit}>
{props.children}
</form>
);
}
FormWrapper.propTypes = {
handleSubmit: PropTypes.func,
children: PropTypes.any,
};
FormWrapper.defaultProps = {
handleSubmit: () => {},
children: {},
};
return reduxForm({
form: formName,
})(FormWrapper);
}
export default withForm;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment