npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

om-lightweightform

v1.6.0

Published

A lightweight React hook for form validation without Formik or Yup.

Readme

om-lightweightform

Keywords: React form validation, custom hook, email validation, phone validation, form state management, lightweight form library, input validation, form submission, React hooks, zero-dependency validation, react, hook, validation, form-validation, react-hook, validation-hook, input-validation, error-messages, realtime-validation, custom-validation, react-forms, form-check, type-checking, use-validation, field-validation, form-error-handling, react-validation-dev, validator, validator-dev, validation-dev, form library, React form hook, validation library, JavaScript validation, frontend validation, user input validation, form handling, React components, state management, error handling, form validation rules

A lightweight React hook for form validation without Formik or Yup.

Description

om-lightweightform is a simple Email,phone Validator, zero-dependency React hook that provides form validation capabilities. It allows you to manage form state, validate inputs based on custom rules, and handle form submissions easily. This hook is designed to be lightweight and easy to use, making it a great alternative to heavier libraries like Formik and Yup.

Om light weight form support Latest version of React.

Note: The Omlightweight-form React package is built using the latest React version and supports React 17 through 19.

Installation

Install the package via npm:

npm install om-lightweightform

Usage

Import the useSimpleForm hook into your React component:

import { useSimpleForm } from 'om-lightweightform';

Then, use it in your component:

const { values, errors, isValid, handleChange, handleSubmit } = useSimpleForm(
  initialValues,
  validations
);

API Reference

useSimpleForm(initialValues, validations)

Parameters

  • initialValues (Object): An object containing the default values for the form fields.
  • validations (Object): An object defining validation rules for each field. Each field can have the following rules:
    • required (boolean): Whether the field is required.
    • minLength (number): Minimum length for the field value.
    • pattern (RegExp): A regular expression to validate the field value.
    • patternMessage (string): Custom error message for pattern validation.

Returns

  • values (Object): Current values of the form fields.
  • errors (Object): Current validation errors for each field.
  • isValid (boolean): Whether the entire form is valid.
  • handleChange (function): Event handler for input changes. Pass this to the onChange prop of your inputs.
  • handleSubmit (function): Function that returns an event handler for form submission. Pass a callback function to handle valid form submissions.

Example

Here's a complete example of a simple form using useSimpleForm:

import React from 'react';
import { useSimpleForm } from 'om-lightweightform';

function ContactForm() {
  const { values, errors, isValid, handleChange, handleSubmit } = useSimpleForm(
    { name: '', email: '', phone: '' },
    {
      name: { required: true, minLength: 3 },
      email: {
        required: true,
        pattern: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
        patternMessage: 'Enter a valid email address',
      },
      phone: {
        required: true,
        pattern: /^\d{10}$/,
        patternMessage: 'Phone number must be exactly 10 digits',
      },
    }
  );

  const onSubmit = (data) => {
    console.log('Form submitted:', data);
    // Handle form submission
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)} style={{ maxWidth: '400px', margin: '0 auto', padding: '20px' }}>
      <div style={{ marginBottom: '15px' }}>
        <label style={{ display: 'block', marginBottom: '5px' }}>Name</label>
        <input
          name="name"
          value={values.name}
          onChange={handleChange}
          style={{ width: '100%', padding: '8px', boxSizing: 'border-box' }}
        />
        <p style={{ color: 'red', fontSize: '14px', margin: '5px 0 0 0' }}>{errors.name}</p>
      </div>

      <div style={{ marginBottom: '15px' }}>
        <label style={{ display: 'block', marginBottom: '5px' }}>Email</label>
        <input
          name="email"
          type="email"
          value={values.email}
          onChange={handleChange}
          style={{ width: '100%', padding: '8px', boxSizing: 'border-box' }}
        />
        <p style={{ color: 'red', fontSize: '14px', margin: '5px 0 0 0' }}>{errors.email}</p>
      </div>

      <div style={{ marginBottom: '15px' }}>
        <label style={{ display: 'block', marginBottom: '5px' }}>Phone Number</label>
        <input
          name="phone"
          type="tel"
          value={values.phone}
          onChange={handleChange}
          style={{ width: '100%', padding: '8px', boxSizing: 'border-box' }}
        />
        <p style={{ color: 'red', fontSize: '14px', margin: '5px 0 0 0' }}>{errors.phone}</p>
      </div>

      <button
        type="submit"
        disabled={!isValid}
        style={{
          padding: '10px 20px',
          backgroundColor: isValid ? '#007bff' : '#ccc',
          color: 'white',
          border: 'none',
          borderRadius: '4px',
          cursor: isValid ? 'pointer' : 'not-allowed'
        }}
      >
        Submit
      </button>
    </form>
  );
}

export default ContactForm;

License

MIT