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

react-form-genius

v1.3.4

Published

Lightweight dynamic form builder for React

Readme

FormGenius

A powerful, schema-driven React form generator. Define your form structure once, and FormGenius handles validation, error handling, and edge cases automatically.

Installation

npm install react-form-genius

Note: Requires React 17.0.0 or higher.

Quick Start

import React from "react";
import { FormGenius } from "react-form-genius";

function SimpleForm() {
  return (
    <FormGenius
      schema={{
        name: { type: "text", label: "Name", required: true },
        email: { type: "email", label: "Email", required: true },
        message: { type: "text", label: "Message", required: true, minLength: 10 },
      }}
      onSubmit={(data) => console.log(data)}
    />
  );
}

Form Types

Multi-Step Form

<FormGenius
  schema={{
    firstName: { type: "text", label: "First Name", required: true },
    lastName: { type: "text", label: "Last Name", required: true },
    email: { type: "email", label: "Email", required: true },
    username: { type: "text", label: "Username", required: true },
    password: { type: "password", label: "Password", required: true },
  }}
  steps={[
    ["firstName", "lastName", "email"],
    ["username", "password"],
  ]}
  showStepIndicators={true}
  onSubmit={(data) => console.log(data)}
/>

Array Form (Dynamic Lists)

<FormGenius
  schema={{
    skills: {
      type: "text",
      label: "Skills",
      isArray: true,
      minItems: 1,
      maxItems: 10,
      addButtonLabel: "Add Skill",
      placeholder: "Enter a skill",
    },
  }}
  onSubmit={(data) => console.log(data)}
/>

Conditional Form

<FormGenius
  schema={{
    accountType: { type: "text", label: "Account Type", required: true },
    companyName: {
      type: "text",
      label: "Company Name",
      dependsOn: "accountType",
      showIf: (value) => value === "business",
      required: true,
    },
  }}
  onSubmit={(data) => console.log(data)}
/>

Form with Default Values

<FormGenius
  defaultValues={{ name: "John Doe", email: "[email protected]" }}
  schema={{
    name: { type: "text", label: "Name", required: true },
    email: { type: "email", label: "Email", required: true },
  }}
  onSubmit={(data) => console.log(data)}
/>

Advanced Features

Custom Validation

<FormGenius
  schema={{
    password: {
      type: "password",
      label: "Password",
      required: true,
      validate: (value) => {
        if (value.length < 8) return "Must be at least 8 characters";
        if (!/[A-Z]/.test(value)) return "Must contain uppercase letter";
        if (!/[a-z]/.test(value)) return "Must contain lowercase letter";
        if (!/\d/.test(value)) return "Must contain number";
        return undefined;
      },
    },
    confirmPassword: {
      type: "password",
      label: "Confirm Password",
      required: true,
      validate: (value, allValues) => {
        return value !== allValues.password ? "Passwords do not match" : undefined;
      },
    },
  }}
  onSubmit={(data) => console.log(data)}
/>

Pattern Validation

<FormGenius
  schema={{
    username: {
      type: "text",
      label: "Username",
      required: true,
      pattern: /^[a-zA-Z0-9_]+$/,
      placeholder: "Only letters, numbers, and underscores",
    },
    phone: {
      type: "tel",
      label: "Phone",
      pattern: /^\+?[\d\s-()]+$/,
    },
  }}
  onSubmit={(data) => console.log(data)}
/>

Custom Rendering

<FormGenius
  schema={{
    bio: {
      label: "Bio",
      required: true,
      render: ({ value, onChange, error, id, name }) => (
        <div>
          <textarea
            id={id}
            name={name}
            value={value || ""}
            onChange={(e) => onChange(e.target.value)}
            style={{
              width: "100%",
              padding: "8px",
              border: error ? "2px solid red" : "1px solid #ccc",
            }}
          />
          {error && <div style={{ color: "red", fontSize: "12px" }}>{error}</div>}
        </div>
      ),
    },
    country: {
      label: "Country",
      required: true,
      render: ({ value, onChange, error, id, name }) => (
        <select id={id} name={name} value={value || ""} onChange={(e) => onChange(e.target.value)}>
          <option value="">Select country</option>
          <option value="usa">USA</option>
          <option value="uk">UK</option>
        </select>
      ),
    },
  }}
  onSubmit={(data) => console.log(data)}
/>

Layouts

// Stack (default)
<FormGenius layout="stack" schema={{...}} />

// Grid (3 columns)
<FormGenius layout="grid" schema={{...}} />

// Two-column
<FormGenius layout="two-column" schema={{...}} />

Input Sizes

<FormGenius
  variant={{ size: "medium" }} // Global
  schema={{
    small: { type: "text", label: "Small", variant: { size: "small" } },
    large: { type: "text", label: "Large", variant: { size: "large" } },
  }}
  onSubmit={(data) => console.log(data)}
/>

Custom Buttons

<FormGenius
  schema={{ name: { type: "text", label: "Name", required: true } }}
  buttonProps={{
    submit: { style: { backgroundColor: "#10b981", color: "white" } },
  }}
  renderButtons={{
    submit: ({ onClick, label }) => (
      <button onClick={onClick} style={{ backgroundColor: "#10b981" }}>
        ✓ {label}
      </button>
    ),
  }}
  onSubmit={(data) => console.log(data)}
/>

Supported Input Types

text, email, password, number, range, date, datetime-local, time, url, tel, search, checkbox

Field Options

Basic

  • type - HTML input type
  • label - Field label
  • required - Required field
  • placeholder - Placeholder text

Validation

  • min / max - Min/max value or date
  • minLength / maxLength - String length
  • pattern - Regex pattern
  • validate - Custom validation function

Array Fields

  • isArray - Enable dynamic list
  • minItems / maxItems - Array size limits
  • defaultItem - Default value for new items
  • addButtonLabel / removeButtonLabel - Button labels

Conditional

  • dependsOn - Field name to depend on
  • showIf - Function to show/hide field

Styling

  • className - CSS class (string or function)
  • inputProps - Additional input props
  • variant - Size variant: { size: "small" | "medium" | "large" }

Custom

  • render - Custom render function

API Reference

<FormGenius
  schema={FormSchema} // Required
  onSubmit={(data) => void} // Required
  onError?: (error: Error) => void
  defaultValues?: Record<string, any>
  layout?: "stack" | "grid" | "two-column"
  steps?: string[][]
  showStepIndicators?: boolean
  variant?: { size?: "small" | "medium" | "large" }
  labels?: { next?: string; prev?: string; submit?: string }
  buttonProps?: { prev?: object; next?: object; submit?: object }
  renderButtons?: { prev?: function; next?: function; submit?: function }
/>

Error Handling

<FormGenius
  schema={{...}}
  onSubmit={(data) => {...}}
  onError={(error) => {
    console.error("Form error:", error);
    // Handle errors
  }}
/>

FormGenius automatically handles: null/undefined values, empty strings, whitespace trimming, NaN/Infinity, invalid dates, email/URL validation, pattern failures, and custom validation errors.

License

MIT


Happy form building! 🎉