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

smart-react-form

v0.1.0

Published

Lightweight React form hook with validators, file support, and smart reset functions

Readme

Smart React Form

Minimal, beginner-friendly React form helper with SmartForm, validators, and reusable input components.
No need for useState, useEffect, or prop drilling for forms. Perfect for dashboards, registration forms, and form-heavy apps.

🌟 Features

  • useSmartForm Hook: Manage form state, nested fields, validation, and reset easily.
  • Validators (v): Built-in validators for numbers, integers, positive values, email, Bangladeshi phone, required, file size, oneOf, min/max length.
  • Reusable Inputs:
    • FormInput – text, number, checkbox
    • FormFileInput – file input with reset support
    • FormSelect – dropdown with validation
  • Nested Fields: Support for fields like address.city.
  • File Reset Support: Automatically reset file inputs.
  • Clear & Simple: Minimal boilerplate for React forms
  • Error Summary: You can show error Summary top or bottom on the UI.

🛠 Installation

npm install smart-react-form

or

yarn add smart-react-form

Requires React >= 16.8


📦 Package Structure

react-smart-crud/
├── src/
│   ├── helpers.js          # getByPath & setByPath
│   ├── validators.js       # All built-in validation functions
│   ├── useSmartForm.js     # Main custom hook
│   ├── FormInput.jsx       # Text / number / checkbox input
│   ├── FormFileInput.jsx   # File input with reset
│   └── FormSelect.jsx      # Select dropdown input
├── index.js                # Single entry point exports
└── index.d.ts              # Type definitions

🎨 How SmartForm Works – Visual Flow

┌─────────────┐
│ User Types  │
└─────┬───────┘
      │ onChange
      ▼
┌─────────────┐
│ useSmartForm│
│ bind(name)  │
│ updates     │
│ values      │
└─────┬───────┘
      │ validate()
      ▼
┌─────────────┐
│ validators  │
│  v.required │
│  v.number   │
│  v.email    │
└─────┬───────┘
      │ errors?
      ▼
┌─────────────┐
│ FormInput   │
│ FormSelect  │
│ FormFile    │
└─────────────┘

⚡ Basic Usage – SmartForm Demo Form

import React from "react";
import { useSmartForm, FormInput, FormFileInput, FormSelect, v } from "react-smart-crud";

export default function RegisterForm() {
  const form = useSmartForm();

  const onSubmit = (data) => {
    console.log("Final Data:", data);
    form.reset(); // reset all fields after submission
  };

  return (
    <form onSubmit={form.submit(onSubmit)} className="space-y-4">
      {/* Name */}
      <FormInput
        form={form}
        name="name"
        placeholder="Full Name"
        validators={[v.required("Name is required"), v.minLen(5)]}
      />

      {/* Age */}
      <FormInput
        form={form}
        name="age"
        type="number"
        placeholder="Age"
        validators={[v.required(), v.number(), v.min(18)]}
      />

      {/* Role */}
      <FormSelect
        form={form}
        name="role"
        validators={[v.required()]}
      >
        <option value="">Select Role</option>
        <option value="admin">Admin</option>
        <option value="user">User</option>
      </FormSelect>

      {/* Phone */}
      <FormInput
        form={form}
        name="phone"
        placeholder="+8801XXXXXXXXX"
        validators={[v.required(), v.phoneBD()]}
      />

      {/* Avatar */}
      <FormFileInput
        form={form}
        name="avatar"
        validators={[v.fileSize(500)]} // Max 500kb
      />

      {/* Checkbox */}
      <FormInput
        form={form}
        name="agree"
        type="checkbox"
        label="I agree"
        validators={[v.required("You must agree")]}
      />

      <button type="submit">Register</button>
    </form>
  );
}


⚡ Error Summary

Display all form errors at once in a summary box.

Usage : (Top or Bottom on Form)

<ErrorSummary errors={form.errors} />

Props:

errors – object from useSmartForm, e.g. form.errors.

Example output:

Please fix errors:

  • Name is required
  • Age must be at least 18
  • Invalid Bangladeshi phone number

Notes:

Automatically hides if there are no errors.

Works with individual field errors for better UX



📝 Validator Examples

| Validator | Usage Example | Notes | | ------------------- | ----------------------------- | ------------------------------- | | v.required() | v.required("Name required") | Works for string, boolean, file | | v.number() | v.number() | Checks for number | | v.integer() | v.integer() | Must be integer | | v.positive() | v.positive() | Number > 0 | | v.minLen(n) | v.minLen(5) | Minimum string length | | v.exactLen(n) | v.exactLen(11) | Exact length | | v.startsWith(str) | v.startsWith("+880") | Must start with string | | v.email() | v.email() | Valid email format | | v.phoneBD() | v.phoneBD() | Valid Bangladeshi phone | | v.oneOf([...]) | v.oneOf(["admin","user"]) | Must be one of the options | | v.fileSize(kb) | v.fileSize(500) | Max file size in KB |


✅ Features Recap & How to Implement

  1. Form State Management

    const form = useSmartForm();
    form.bind("fieldName"); // bind to inputs
  2. Validation

    validators={[v.required(), v.number()]}
  3. Nested Fields

    <FormInput form={form} name="address.city" />
  4. File Input with Reset

    <FormFileInput form={form} name="avatar" validators={[v.fileSize(500)]} />
  5. Dropdown / Select

    <FormSelect form={form} name="role">
      <option value="admin">Admin</option>
    </FormSelect>

📌 Quick Tips

  • Always wrap input fields with bind or use FormInput, FormFileInput, FormSelect.
  • For files, reset automatically handled by SmartForm’s reset() or resetField(name).
  • Nested objects supported using dot notation: address.city.