Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.
/ exeform Public archive

Forms with minimum code and maximum performance

License

Notifications You must be signed in to change notification settings

exeto/exeform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

exeform

npm npm bundle size coverage license

Forms with minimum code and maximum performance

THIS PACKAGE IS NO LONGER MAINTAINED

Features

  • Maximum out-of-the-box performance
  • Modern and minimalistic API
  • Small size, 2 KB (minified and gzipped)
  • No dependencies

Install

Install using yarn:

yarn add exeform

Or npm:

npm install exeform

Basic Example

import React from 'react';
import { Form, useForm, useField } from 'exeform';

const validate = (values) => {
  const errors = {};

  if (!values.email) {
    errors.email = 'This field is required';
  }

  if (!values.password) {
    errors.password = 'This field is required';
  }

  return errors;
};

const TextField = ({ name, ...rest }) => {
  const { field, meta } = useField(name);
  const error = meta.touched ? meta.error : null;

  return (
    <div>
      <input {...field} {...rest} />
      {error ? <div>{error}</div> : null}
    </div>
  );
};

const Login = () => {
  const form = useForm({
    validate,
    initialValues: {
      email: '',
      password: '',
    },
  });

  const handleSubmit = (event) => {
    event.preventDefault();
    form.touchAllFields();

    if (form.isValid) {
      console.log(form.values);
      form.reset();
    }
  };

  return (
    <Form form={form} onSubmit={handleSubmit}>
      <TextField name="email" placeholder="email" />
      <TextField name="password" placeholder="password" type="password" />
      <button type="submit">Submit</button>
    </Form>
  );
};

License

MIT © Timofey Dergachev

About

Forms with minimum code and maximum performance

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages