0.6.1 • Published 6 months ago

relidate v0.6.1

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

relidate

Form validation library for React.

Quickstart

import { useForm } from 'relidate';
import { minLength, required } from 'relidate/validators';

export function SignUpForm() {
  const {
    fields: { email, password, confirmPassword },
    register,
    update,
    touch,
    isValid,
  } = useForm({
    initialState: {
      email: '',
      password: '',
      confirmPassword: '',
    },
    validators: {
      email: [required],
      password: [required, minLength(8)],
      confirmPassword: [
        required,
        (value, state) =>
          value === state.password || 'Passwords should be equal',
      ],
    },
  });

  return (
    <form>
      <h3>Sign Up</h3>
      <input
        type="email"
        placeholder="Email"
        // Returns value, onChange, onBlur
        {...register('email')}
      />
      <input
        type="password"
        placeholder="Password"
        // Or you can register those fields manually
        value={password.value}
        onChange={(e) => update('password', e.target.value)}
        onBlur={() => touch('password')}
      />
      <input
        type="password"
        placeholder="Confirm password"
        {...register('confirmPassword')}
      />
      // Show error
      {confirmPassword.touched && <p>{confirmPassword.errors[0]}</p>}
      <button type="submit" disabled={!isValid}>
        Sign Up
      </button>
    </form>
  );
}
0.6.1

6 months ago

0.6.0

6 months ago

0.5.0

6 months ago

0.4.6

6 months ago

0.4.5

6 months ago

0.4.4

6 months ago

0.4.3

6 months ago

0.4.2

6 months ago

0.4.1

6 months ago

0.4.0

6 months ago

0.3.4

6 months ago

0.3.3

7 months ago

0.3.2

7 months ago