Elmar

React hook form

7 feb 2024

This is a snippet i use in all my React projects. A wrapper for the react-hook-form useForm hook that takes in a schema to make it type-safe and it returns a FormField component that removes the need for having to add the control prop to the FormField component.

      import {  } from "zod";

import {  } from "./use-form";

const  = () => {
  const  = ({
    : .({
      : .(),
      : .(),
    }),
  });

  return (
    <>
      <. ="street">
        {({  }) => < {...} />}
      </.>
      <. ="
">
{({ }) => < {...} />} </.> </> ); };