0.1.0 • Published 6 years ago

react-use-form v0.1.0

Weekly downloads
28
License
GPL-3.0
Repository
github
Last release
6 years ago

react-use-form

Custom react hook for HTML forms

usage

npm install --save react-use-form react@^16.7.0-alpha.0 react-dom@^16.7.0-alpha.0

import { Form, Input } from 'react-use-form';

const handleSubmit = (values) => {
  if (values.surname === 'Jetson') {
    return values.name === 'George';
  }
  else {
    return true;
  }
};

const isValidSurname = (surname) => {
  return ['Jetson', 'Flinstone', 'Simpson'].findIndex(surname) >= 0;
};

const MyForm = ({ initialValues }) => {
  return (
    <Form onSubmit={handleSubmit}>
      <Input InputAs="input" name="name" />
      <Input InputAs="input" name="surname" validate={isValidSurname} />
      <button type="submit">Submit</button>
    </Form>
  );
};

export default MyForm;
0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago