Socket
Book a DemoInstallSign in
Socket

exeform

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exeform

Forms with minimum code and maximum performance

latest
Source
npmnpm
Version
0.6.0
Version published
Maintainers
1
Created
Source

exeform

npm npm bundle size coverage license

Forms with minimum code and maximum performance

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

Keywords

form

FAQs

Package last updated on 20 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts