New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-hook-form-zod

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hook-form-zod

Typesafe forms with React Hook Form and Zod

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
221
decreased by-19.93%
Maintainers
1
Weekly downloads
 
Created
Source

react-hook-form-zod

npm version

react-hook-form-zod is a library that combines react-hook-form and zod to create forms with validation.

Its primary purpose is to reduce the boilerplate required to use zod with react-hook-form.

Install

npm install react-hook-form-zod zod
yarn add react-hook-form-zod zod
pnpm add react-hook-form-zod zod

Usage

WITHOUT react-hook-form-zod:

import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";

const schema = z.object({
  name: z.string().min(3).max(10),
  age: z.number().min(18),
});

type FormValues = z.infer<typeof schema>;

function Form() {
  const form = useForm<FormValues>({
    resolver: zodResolver(schema),
  });

  // ...
}

WITH react-hook-form-zod:

import { useForm } from "react-hook-form-zod";
import { z } from "zod";

const schema = z.object({
  name: z.string().min(3).max(10),
  age: z.number().min(18),
});

function Form() {
  const form = useForm({
    schema,
  });

  // ...
}

API Reference

The API is identical to react-hook-form with the exception of the useForm hook. useForm takes three additional options which correspond to the arguments of the zodResolver factory function:

  • schema: a zod schema (required)
  • schemaOptions: options for the zod schema
  • factoryOptions: options for the hookform resolver factory

Keywords

FAQs

Package last updated on 30 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc