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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-decode-form

v0.1.2

Published

typed form

Readme

react-decode-form

What?

react-decode-form is a custom hooks library designed to help manage form data in your React applications. It provides a simple and efficient way to separate the management of internal and external data structures. The form component acts as the boundary, converting the data into the correct structure.

How?

To achieve this separation and conversion, react-decode-form operates using four key components:

  1. External structure: This is the user-facing data structure. It should be easily convertible to a string. Examples include units like MM, CM, M, etc.
  2. Internal structure: This represents the correct data types that your application uses. If you want to standardize the units across your application, you might want to convert everything to MM, for example.
  3. Internal-to-external conversion function: A function that handles the conversion from the internal structure to the external structure. It also handles validation.
  4. External-to-internal conversion function: A function that converts from the external structure to the internal structure.

Installation

npm i react-decode-form

Usage

Here's an example of using react-decode-form:

import { useForm, FormSchema } from 'react-decode-form';

const schema = {
  width: {
    in: MM,  // External structure
    ex: CM,  // Internal structure
    i2e: mm2cm, // Internal-to-external conversion function
    e2i: cm2mm, // External-to-internal conversion function
  },
  height: {
    in: MM,  // External structure
  },
} satisfies FormSchema;

const Form: React.FC = () => {
  const { register, values } = useForm(schema, {
    defaultValues: {
      width: mkMM(0),
      // height is not specified in defaultValues, so its type will be 'number | null'
    },
  });

  const width = values.width; // number
  const height = values.height; // number | null
  return (
    <div>
      <input {...register('width')} type="number" />
      <input {...register('height')} type="number" />
    </div>
  );
};

In this example, the schema defines the external and internal structures, along with the conversion functions. If no conversion is required, elements 2-4 (in,i2e,e2i) can be omitted. It provides a similar API to react-hook-form, including register, getValue, setValue, errors, <Controller/>, etc.

The library ensures type safety. The getValue() and values methods return the correct data structure in your internal world. The type of getValue() and values corresponds to the internal data structure. If defaultValues aren't specified for a field, the type will be T | null.

Contributing

Welcome

License

MIT