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-declarative-hook-form

v1.0.0

Published

Library to automatically generate forms and pre-fill with external data.

Downloads

27

Readme

React Declarative Hook Form

This library allows you to create forms without dealing with any JSX but still leverage the work from the react-hook-form ecosystem. The idea for this library is to be able to automatically generate a form based on a schema and pre-fill the form with a json object.

Installation & Usage

npm i react-hook-form react-declarative-hook-form

And import react-hook-form before importing react-declarative-hook-form

Example

More examples can be found in the the test-app directory were the library is tested with playwright.

Simple user form with no pre filled data.

const user: Schema = {
  name: {
    type: "text",
  },
  password: {
    type: "password",
  },
};

const [result, setResult] = useState<typeof user>();
return <DeclarativeForm<typeof user> schema={user} onSubmit={setResult} />;

User schema with pets as an array that can be dynamically added in the form

const user: Schema = {
  name: {
    type: "text",
  },
  password: {
    type: "password",
  },
  pets: [
    {
      name: { type: "text" },
      age: { type: "number" },
    },
  ],
};

const userFromDatabase = {
  name: "Bob",
  password: "abc",
  pets: [
    { name: "Alpha", age: 10 },
    { name: "Beta", age: 5 },
  ],
};

const [result, setResult] = useState<typeof user>();
return (
  <DeclarativeForm<typeof user>
    schema={user}
    defaultValues={userFromDatabase}
    onSubmit={setResult}
  />
);

User schema with pets and photo album with checkbox and photos.

const user: Schema = {
  name: {
    type: "text",
  },
  password: {
    type: "password",
  },
  pets: [
    {
      name: { type: "text" },
      age: { type: "number" },
    },
  ],
  photoAlbum: {
    public: { type: "checkbox" },
    photos: [{ url: { type: "text" } }],
  },
};

const userFromDatabase = {
  name: "Bob",
  password: "abc",
  pets: [
    { name: "Alpha", age: 10 },
    { name: "Beta", age: 5 },
  ],
  photoAlbum: {
    public: false,
    photos: [
      { url: "www.example.com/photo1" },
      { url: "www.example.com/photo2" },
    ],
  },
};

const [result, setResult] = useState<typeof user>();
return (
  <DeclarativeForm<typeof user>
    schema={user}
    defaultValues={userFromDatabase}
    onSubmit={setResult}
  />
);

Docs

TODO

Styling

React Declarative Hook Form comes with a default theme that allows for creating automatic forms with native input elements for all input elements specified in the HTML standard. The default theme can be replaced by interacting with the InputRepository singleton to allow for support for your favorite UI library or for creating custom input types that does not exist in the HTML standard.

Example function that replaces password and text fields with Material UI versions. A full module for this is available in the react-declarative-hook-form-mui directory.

function init(variant: string) {
  const inputs = {
    password: React.forwardRef((props: any, ref: any) => (
      <Input type="password" ref={ref} {...props} />
    )),
    text: React.forwardRef((props: any, ref: any) => (
      <TextField
        ref={ref}
        variant={variant}
        {...props}
        label={props.placeholder}
        placeholder={""}
      />
    )),
  };
  Object.entries(inputs).forEach(([type, component]) => {
    InputRepository.getRepository().set(type, component);
  });
}

Development

For easier development of react-declarative-hook-form using the test app symlink react and react-declarative-hook-form.

From the root directory do:

cd ./react-declarative-hook-form/node_modules/react
npm link
cd ../../
npm link
cd ../test-app/
npm link react
npm link react-declarative-hook-form