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

@7span/react-form

v0.1.0

Published

Dynamic forms for React - Generate forms from JSON field definitions.

Downloads

104

Readme

@7span/react-form

Dynamic forms for React - Generate forms from JSON field definitions.

Installation

npm install @7span/react-form

Quick Start

import {
  ReactForm,
  ReactFormFields,
  ReactFormField,
  ReactFormCreate,
  ReactFormUpdate,
} from "@7span/react-form";

function App() {
  const fields = ["name", { name: "email", value: "[email protected]" }];

  const create = (context) => {
    return Promise.resolve({ values: context.values });
  };

  const update = (itemId, context) => {
    return Promise.resolve({ values: context.values });
  };

  return (
    <ReactForm fields={fields} create={create} update={update}>
      {({ context }) => (
        <>
          <ReactFormFields>
            {({ values }) => (
              <>
                <ReactFormField name="name">
                  {({ field, label }) => (
                    <>
                      <label>{label}</label>
                      <input {...field} />
                    </>
                  )}
                </ReactFormField>
                <ReactFormField name="email">
                  {({ field, label }) => (
                    <>
                      <label>{label}</label>
                      <input type="email" {...field} />
                    </>
                  )}
                </ReactFormField>
              </>
            )}
          </ReactFormFields>
          <ReactFormCreate />
          <ReactFormUpdate />
        </>
      )}
    </ReactForm>
  );
}

Components

  • ReactForm - Root form component
  • ReactFormFields - Field container component
  • ReactFormField - Individual field wrapper
  • ReactFormCreate - Create button component
  • ReactFormUpdate - Update button component
  • ReactFormDelete - Delete button component
  • ReactFormArchive - Archive button component
  • ReactFormUnarchive - Unarchive button component
  • ReactFormError - Error display component

Features

  • Dynamic form generation from field definitions
  • CRUD operations (Create, Read, Update, Delete, Archive, Unarchive)
  • State management using React Context
  • Field configuration (strings or objects)
  • Error handling with customizable error adapters
  • Granular components for flexible composition
  • Schema Support - Accepts custom validation schemas (Zod, Yup, or any validation library)
  • Custom Validation - Provide your own validateSchema function
  • Field Extraction - Custom schemaToFields function to extract fields from schemas
  • Field-level and form-level validation errors
  • Built-in error management utilities

Validation

The library supports validation through custom validateSchema and schemaToFields functions. You can use any validation library (Zod, Yup, or custom). Install the validation library of your choice:

# For Zod (example)
npm install zod@^4.2.1

# For Yup (example)
npm install yup@^1.7.1

Basic Usage with Validation

import { ReactForm, ReactFormProvider, ReactFormField } from "@7span/react-form";
import { z } from "zod";

const schema = z.object({
  name: z.string().min(2, "Name must be at least 2 characters"),
  email: z.string().email("Invalid email address"),
});

// Custom validation function
const validateSchema = async (schema, values) => {
  const result = schema.safeParse(values);
  if (result.success) {
    return { success: true, errors: {} };
  }
  
  const fieldErrors = result.error.issues.reduce((acc, issue) => {
    const field = issue.path[0]; // "id", "email", etc.
    if (!field) return acc;

    acc[field] = {
      message: issue.message, // ← EXACT message from schema
    };
    return acc;
  }, {});
  
  return { success: false, errors: fieldErrors };
};

// Custom schema to fields converter
const schemaToFields = (schema) => {
  if (schema && schema.shape && typeof schema.shape === 'object') {
    return Object.keys(schema.shape).map((key) => {
      const defaultValue = schema.shape[key]._def.defaultValue();
      const label = schema.shape[key]._def.description;
      return {
        name: key,
        label: label || key.charAt(0).toUpperCase() + key.slice(1),
        value: defaultValue,
      };
    });
  }
  return [];
};

function MyForm() {
  return (
    <ReactFormProvider
      schemaToFields={schemaToFields}
      validateSchema={validateSchema}
    >
      <ReactForm
        fields={["name", "email"]}
        schema={schema}
        create={async (context) => {
          console.log("Valid data:", context.values);
        }}
      >
        {({ context }) => (
          <>
            <ReactFormField name="name">
              {({ field, label, error }) => (
                <>
                  <label>{label}</label>
                  <input {...field} />
                  {error && <span className="error">{error.message}</span>}
                </>
              )}
            </ReactFormField>
            <ReactFormField name="email">
              {({ field, label, error }) => (
                <>
                  <label>{label}</label>
                  <input type="email" {...field} />
                  {error && <span className="error">{error.message}</span>}
                </>
              )}
            </ReactFormField>
          </>
        )}
      </ReactForm>
    </ReactFormProvider>
  );
}

See VALIDATION.md for detailed validation documentation.

Exports

The package exports all components, context utilities, and error management functions:

import {
  // Components
  ReactForm,
  ReactFormFields,
  ReactFormField,
  ReactFormCreate,
  ReactFormUpdate,
  ReactFormDelete,
  ReactFormArchive,
  ReactFormUnarchive,
  ReactFormError,
  // Context & Providers
  ReactFormProvider,
  useReactForm,
  // Utilities
  attrSerializer,
  // Error Management
  getFieldError,
  setFieldError,
  setFieldErrors,
  clearAllErrors,
  clearFieldError,
} from "@7span/react-form";

Documentation

See the documentation for more details.