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

@hero-u/form-core

v1.0.0

Published

hero-u path based form core

Readme

@hero-u/form-core

Framework-agnostic form state management with a pub/sub subscription model.

Installation

npm install @hero-u/form-core

Core concepts

State is stored in a stable ref object (FormRefObject) created once per FormProvider. Components subscribe to specific field paths via useSyncExternalStore; only subscribed components re-render when their path changes.

setFieldValue uses immutable path cloning (setIn): writing transactions.0.checked shallow-clones every container along that path, so both useFieldValue('transactions.0.checked') and useFieldValue('transactions') receive the update. Sibling paths keep their original references.

Emit strategy 'related' (default): notifying a path also notifies any ancestor or descendant subscriptions, matching the cloning scope exactly.

Basic usage

import { FormProvider, useFormContext, useFieldValue } from '@hero-u/form-core';

interface Values {
  name: string;
  age: number;
}

// Provider
<FormProvider<Values>
  initialValues={{ name: '', age: 0 }}
  onValuesChange={values => console.log(values)}
>
  <MyForm />
</FormProvider>

// Read a field reactively
const name = useFieldValue<string>('name');

// Read/write via form ref
const form = useFormContext<Values>();
form.getValues();
form.setFieldValue('name', 'Alice');
form.setFieldValue('items.0.checked', true);           // fine-grained write
form.setValues({ name: 'Alice', age: 30 });            // shallow-merge multiple fields
form.setFieldValue('items', prev => [...prev, item]);  // functional update
form.resetFields();

API

<FormProvider>

| Prop | Type | Description | |------|------|-------------| | initialValues | T \| (() => T) | Initial form values | | onValuesChange | (values: T) => void | Called after every field write | | validate | (values: T) => Errors \| Promise<Errors> | Form-level validator | | emitCompareStrategy | 'equal' \| 'related' \| 'all' \| fn | Subscription notification strategy (default 'related') |

Hooks

| Hook | Returns | Description | |------|---------|-------------| | useFormContext<T>() | FormRefObject<T> | Access the form ref | | useFieldValue<V>(name) | V | Subscribe to a field value | | useFieldHandler(name, opts?) | onChange fn | Standard change handler (supports type: 'checkbox') | | useField(name) | { value, error, touched } | Field state snapshot | | useFormSubmit(onSubmit) | { handleSubmit, isSubmitting } | Submit with validation | | useFormSubmitCount() | number | How many times the form was submitted | | useFormErrors() | Errors | Current validation errors | | useFormValidating() | boolean | Whether async validation is running |

FormRefObject methods

| Method | Description | |--------|-------------| | getValues() | Current values snapshot (non-reactive) | | setFieldValue(path, value \| updater) | Write one field (immutable path clone) | | setValues(partial \| updater) | Shallow-merge into values | | resetFields() | Restore initialValues, clear errors & touched | | getFieldValue(path) | Non-reactive field read | | getFieldError(path) | Current error for a field | | waitForValidation() | Promise<Errors> — resolves after debounced validation settles |

Path notation

Paths follow lodash convention: 'a.b', 'items[0].name', or an array ['items', 0, 'name'].

Validation

import { createValidate, createRequiredFieldValidate } from '@hero-u/form-core';

// Field-level (attach via Field component or setFieldValidate)
const validateAge = createValidate<number>(({ value }) => {
  if (value < 0) return 'Must be non-negative';
});

// Required shorthand
const required = createRequiredFieldValidate('This field is required');

// Form-level
<FormProvider validate={values => {
  const errors: any = {};
  if (!values.name) errors.name = 'Required';
  return errors;
}}>

FieldDefaultPropsProvider

Propagate disabled (and other default props) to all Field descendants:

<FieldDefaultPropsProvider disabled={isLoading}>
  <MyForm />
</FieldDefaultPropsProvider>

License

MIT