An easy-to-use super customisable form validation library for React.

Overview

react-use-form-validate

Super customizable validation library for forms in react

NPM JavaScript Style Guide

Install

npm install --save react-use-form-validate

Usage

import { useValidation } from 'react-use-form-validate'

const Form = () => {
  let config = {
    fields: {
      email: {
        isRequired: { message: 'Email is Required' },
        isEmail: { message: 'Please enter a valid Email address' }
      },
      password: {
        isRequired: { message: 'Password is Required' }
      }
    },
    onSubmit: context => {
      if (context.isFormValid) {
        console.log('Form is valid and ready to be submitted')
      } else {
        console.log('Form is not valid')
      }
    },
    showErrors: 'blur'
  }

  const { getFieldProps, getFormProps, errors } = useValidation(config)

  return (
    <form {...getFormProps()}>
      <input
        {...getFieldProps('email')}
        type='text'
        placeholder='Email'
      />
      {
        errors.email &&
        <div>
          <p>
            {errors.email}
          </p>
        </div>
      }

      <div>
        <input
          {...getFieldProps('password')}
          type='password'
          placeholder='Password'
        />
        {
          errors.password &&
          <div>
            <p>
              {errors.password}
            </p>
          </div>
        }
      </div>

      <div>
        <button
          type='submit'
        >
          SUBMIT
        </button>
      </div>
    </form >
  )
}

License

MIT © himanshu76200


This hook is created using create-react-hook.

You might also like...

An easy hook to use with expo-calendar library!

useCalendar Hook 🚀 Updated to Expo SDK45 This is an easy hook to use expo-calendar. It allows you: Get access permission to calendar Open settings to

Nov 1, 2022

Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.

Recoil · Recoil is an experimental set of utilities for state management with React. Please see the website: https://recoiljs.org Installation The Rec

Jan 8, 2023

Phonemask - Library for processing the phone input field in the web form. Only native javascript is used

phonemask Library for processing the phone input field in the web form. Only native javascript is used Usage: Adding a library to HTML script type="a

Sep 20, 2022

react-dialog is a custom react hook to use a dialog easily

react-dialog react-dialog is a custom react hook to use a dialog easily. Documentation To use react-dialog follow the documentation. useDialog Returns

Mar 29, 2022

A basic React/NextJS project showing how to use the Flow Client Library (FCL)

A basic React/NextJS project showing how to use the Flow Client Library (FCL)

How to use the Flow Client Library (FCL) with SvelteKit Everything you need to build a SvelteKit project with the Flow Client Library (FCL). For a Sve

Sep 24, 2022

React hook library, ready to use, written in Typescript.

React hook library, ready to use, written in Typescript.

usehooks-ts React hook library, ready to use, written in Typescript. npm i usehooks-ts Created by Julien Caron and maintained with ❤️ by an amazing te

Jan 5, 2023

TryShape is an open-source platform to create shapes of your choice using a simple, easy-to-use interface. You can create banners, circles, polygonal shapes, export them as SVG, PNG, and even as CSS.

TryShape is an open-source platform to create shapes of your choice using a simple, easy-to-use interface. You can create banners, circles, polygonal shapes, export them as SVG, PNG, and even as CSS.

Create, Export, Share, and Use any Shapes of your choice. View Demo · Report Bug · Request Feature 👋 Introducing TryShape TryShape is an opensource p

Dec 26, 2022

Fill the boring catsalud covid vaccine form with a console command

vacunacovid-catsalud-autofullfill form Fill the boring catsalud covid vaccine form with a console command Manual use, pasting in the script in the con

Jul 27, 2021

A Drag & Drop Form Builder base on Bootstrap v4.x

A  Drag & Drop Form Builder base on Bootstrap v4.x

bsFormBuilder 一个基于 Bootstrap (v4.x) + JQuery 的、拖拽的表单构建工具。 特点 1、基于 Bootstrap (v4.x) + JQuery,简单易用 2、拖动的 html 组件,支持通过 Json 自定义扩展 3、组件的属性面板,支持通过 Json 自定义

Aug 25, 2022
Owner
Himanshu Bhardwaz
Hi, I am a full-stack developer trying to master JavaScript Ecosystem. I am familiar with React, Next, Node and currently trying my hands on React Native
Himanshu Bhardwaz
Super tiny color input ranges for React.

react-color-range · Tiny color input for React, made with native input ranges. react-color-range leverages the native input type="range" and CSS linea

Javier Bórquez 3 Jan 16, 2022
Plock is a responsive masonry layout implementation for React. Very simple to use and easy to understand.

About Plock ?? Plock is a responsive masonry layout implementation for React. Very simple to use and easy to understand. Can I see a demo? ?? The demo

Renato Pozzi 130 Dec 9, 2022
An easy to use and simple masonry layout for React Js based on flexbox column.

React Masonry An easy to use and simple masonry layout for React Js based on flexbox column. Live Preview / Demo In Here Basic Usage Masonry Layout <M

null 16 Dec 23, 2022
Easy and simple to use Radio Buttons for your React Native Application.

React Native Simple Radio Buttons Easy and simple to use Radio Buttons for your React Native Application. Installation npm i react-native-custom-radio

Neelesh Ranjan Jha 2 Feb 8, 2022
A Higher Order Component using react-redux to keep form state in a Redux store

redux-form You build great forms, but do you know HOW users use your forms? Find out with Form Nerd! Professional analytics from the creator of Redux

Redux Form 12.6k Jan 3, 2023
🏁 High performance subscription-based form state management for React

You build great forms, but do you know HOW users use your forms? Find out with Form Nerd! Professional analytics from the creator of React Final Form.

Final Form 7.2k Jan 7, 2023
ESLint plugin for react-hook-form

eslint-plugin-react-hook-form react-hook-form is an awsome library which provide a neat solution for building forms. However, there are many rules for

Chuan-Tse Kao 37 Nov 22, 2022
Form handler in React-MobX

MobX Light Form ✨ MobX Form State Management with automatic validation Seperate subjects which manage form data to prevent duplication of data and ens

정윤재 3 Nov 30, 2022
An example of a schema-based form system for React.

React Advanced Form An example of a schema-based form system in React. Define your schema, and pass it into the form. Supports basic conditional schem

Tania Rascia 111 Dec 31, 2022
🪱 Zorm - Type-safe
for React using Zod

React Zorm Type-safe <form> for React using Zod! Features / opinions ?? Type-safe Get form data as a typed object Typo-safe name and id attribute gene

Esa-Matti Suuronen 503 Dec 25, 2022