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

@vtaits/react-hook-form-schema

v2.4.0

Published

Integration of react-hook-form and @vtaits/form-schema

Downloads

128

Readme

NPM dependencies status

@vtaits/react-hook-form-schema

Integration of react-hook-form and @vtaits/form-schema.

Installation

yarn add react-hook-form @vtaits/react-hook-form-schema

or

npm install react-hook-form @vtaits/react-hook-form-schema --save

or

bun add react-hook-form @vtaits/react-hook-form-schema

Examples

Usage

import { useFormSchema } from '@vtaits/react-hook-form-schema';

const {
  handleSubmit,
  renderField,
  setValues,
  parseAndSetValues,
  ...restResult
} = useFormSchema({
		defaultValues,
		getFieldSchema,
		getFieldType,
		mapErrors,
		names,
		...rest
});

const onSubmit = async (values, rawValues) => {
};

<form onSubmit={handleSubmit(onSubmit)}>
  {renderField("field1")}
  {renderField("field2")}

  <hr />

  {renderField("field3", "payload")}
</form>

It similar to react-hook-form but there is some differences:

  • getFieldSchema, getFieldType, names are required. They are described in @vtaits/form-schema;

  • onSubmit receives serialized values as first argument;

  • mapErrors (not required) can map submission errors to set them with @vtaits/form-schema.

renderField

A function for rendering field by name according to its schema. Arguments:

  1. name - required, string, name of field for render;
  2. payload - not required, payload prop of nested field;
  3. parents - not required, stack of parent fields for child field.

setValues

A function for setting runtime values of the form

parseAndSetValues

A function that parses input and sets runtime values of the form

Built-in field types

Dynamic

Field depends from other fields. Example:

import { dynamic } from '@vtaits/react-hook-form-schema/fields/dynamic';

const schema = {
  type: 'dynamic',

  getSchema: ({
    values: {
      otherField,
    },
    phase,
  }) => ({
    type: 'string',
    label: 'String field',
    required: Boolean(otherField),
  }),
};

const getFieldType = (fieldSchema) => {
  if (fieldSchema.type === 'dynamic') {
    return dynamic;
  }

  // ...
}

Parameters:

  • getSchema - required, function, should return schema for render or null. Parameters:

    • values - object of values of form, depends from 2nd argument;

    • phase - current phase ('parse', 'serialize', 'render'). If phase is 'parse', 1st argument is initial values before parsing, otherwise it is current values of form.

    • getFieldSchema - see @vtaits/form-schema;

    • getFieldType - see @vtaits/form-schema;

    • parents - stack of parent fields above current field with runtime values;

  • getSchemaAsync - not required, function. Can be used for asynchronous parsing. Similar to getSchema but should return Promise with result schema;

  • onShow - not required, callback that called when field has shown. Parameters:

    • formResult - result of calling of react-hook-form;

    • name - name of field;

    • schema - result schema of subfield;

    • getFieldSchema - current getFieldSchema;

    • getFieldType - global getFieldType;

    • parents - stack of parent fields above current field with runtime values;

  • onHide - not required, callback that called when field has hidden. Arguments:

    1. formResult - result of calling of react-hook-form;

    2. name - name of field;

    3. getFieldSchema - current getFieldSchema;

    4. getFieldType - global getFieldType;

    5. parents - stack of parent fields above current field with runtime values.

Set

The group of fields. It's comfortable when the dynamic field must render several fields. Example:

import { dynamic } from '@vtaits/react-hook-form-schema/fields/dynamic';
import { set } from '@vtaits/react-hook-form-schema/fields/set';

const schema = {
  type: 'dynamic',

  getSchema: ({
    responsibleType,
  }) => {
    if (responsibleType !== 'human') {
      return null;
    }

    return {
      type: 'set',
      schemas: {
        firstName: {
          type: 'string',
          label: 'First name',
        },

        lastName: {
          type: 'string',
          label: 'Last name',
        },
      },
    };
  },
};

const getFieldType = (fieldSchema) => {
  if (fieldSchema.type === 'dynamic') {
    return dynamic;
  }

  if (fieldSchema.type === 'set') {
    return set;
  }

  // ...
}

Parameters:

  • schemas - required, object whose keys are field names and values are their schemas;

  • render - not required, render function. . Arguments:

    1. renderField - analogous to renderField result of useFormSchema;
    2. names - fields names (keys of schemas);

Utils

renderBySchema

Similar to renderField of the result of useFormSchema, but have more arguments:

  1. formResult - result of react-hook-form;
  2. getFieldSchema - see above;
  3. getFieldType - see above;
  4. getValues - all values at the level of field;
  5. name - the name of the field
  6. payload - see above
  7. parents - see above.
import { renderBySchema } from '@vtaits/react-final-form-schema';