{"id":347048,"date":"2023-03-21T15:01:11","date_gmt":"2023-03-21T15:01:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=347048"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=347048","title":{"rendered":"<span>React: \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/jc\/hw\/st\/jchwst6a3nwlxlscnmuw5tdhmry.png\" data-src=\"https:\/\/habrastorage.org\/webt\/jc\/hw\/st\/jchwst6a3nwlxlscnmuw5tdhmry.png\"\/>  <\/p>\n<p>  Hello, world!<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0441\u0445\u0435\u043c\u0435 (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0435 \u0442\u0430\u043a) \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438 \u0432 <a href=\"https:\/\/ru.reactjs.org\/\">React<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043c\u043d\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439. \u042d\u0442\u0430 \u0441\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <a href=\"https:\/\/react-hook-form.com\/\">React Hook Form<\/a> \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0444\u043e\u0440\u043c \u0438 <a href=\"https:\/\/github.com\/colinhacks\/zod\">Zod<\/a> \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0445\u0435\u043c\u044b \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0440\u0443\u0433\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0438\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u0413\u043b\u0430\u0432\u043d\u044b\u043c\u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 (type inference).<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0434, \u0432\u043e\u0442 <a href=\"https:\/\/github.com\/harryheman\/Blog-Posts\/tree\/master\/react-hook-form-zod\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e? \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0444\u043e\u0440\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f;<\/li>\n<li>\u0432\u043e\u0437\u0440\u0430\u0441\u0442;<\/li>\n<li>\u0430\u0434\u0440\u0435\u0441 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b;<\/li>\n<li>\u043f\u0430\u0440\u043e\u043b\u044c;<\/li>\n<li>\u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 (\u0447\u0435\u043a\u0431\u043e\u043a\u0441) \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u043d\u0435\u043a\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u043f\u043e\u043b\u044f \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438. \u041e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u0445 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044e \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0437\u0434\u043d\u0435\u0435.<\/p>\n<p>  <\/p>\n<h2 id=\"podgotovka-nastroyka-proekta-i-sozdanie-formy\">\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430, \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b<\/h2>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0430 React \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 <a href=\"https:\/\/www.typescriptlang.org\/\">TypeScript<\/a> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/vitejs.dev\/\">Vite<\/a> (\u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/yarnpkg.com\/\">Yarn<\/a>):<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\"># react-hook-form-zod - \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 # react-ts - \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d yarn create vite react-hook-form-zod --template react-ts<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">cd react-hook-form-zod yarn yarn dev<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0448\u0430 \u0444\u043e\u0440\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0439 \u0433\u043b\u0430\u0437\u0443. \u0427\u0442\u043e \u0431\u044b \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0435\u0435 \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438? \u041a\u0430\u043a \u043d\u0430\u0441\u0447\u0435\u0442 <a href=\"https:\/\/tailwindcss.com\/\">Tailwind CSS<\/a>? \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u044d\u0442\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">yarn add -D tailwindcss<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0435\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">npx tailwindcss init<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0438\u043b\u0438 tailwind \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 (reusable) \u0441\u0442\u0438\u043b\u0435\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b <a href=\"https:\/\/tailwindcss.com\/docs\/reusing-styles#extracting-classes-with-apply\">@apply<\/a> \u0432 \u0444\u0430\u0439\u043b\u0435 <code>src\/index.css<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"css\">@tailwind base; @tailwind components; @tailwind utilities;  @layer components {   .title {     @apply text-2xl text-center font-bold leading-tight tracking-tight text-gray-900;   }   .label {     @apply block mb-2 text-sm font-medium text-gray-900 cursor-pointer;   }   .input {     @apply bg-gray-50 border-none outline outline-1 outline-gray-300 text-gray-900 rounded-md w-full p-2.5 focus-visible:outline-2 focus-visible:outline-blue-500 placeholder:text-sm aria-[invalid=\"true\"]:outline-red-500 aria-[invalid=\"true\"]:outline-2;     transition: outline-color 150ms cubic-bezier(0.4, 0, 0.2, 1);   }   .error {     @apply text-red-600 block text-sm absolute;   }   .btn {     @apply text-white outline-none focus:ring-4 font-medium rounded-md text-sm px-5 py-2.5 text-center transition-colors disabled:opacity-50 disabled:cursor-not-allowed;   }   .btn-primary {     @apply bg-primary-500 hover:bg-primary-700 focus:ring-primary-300 disabled:bg-primary-500;   }   .btn-error {     @apply bg-red-500 hover:bg-red-700 focus:ring-red-300 disabled:bg-red-500;   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b\u044b \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 <a href=\"https:\/\/tailwindcss.com\/docs\/theme#extending-the-default-theme\">\u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u0443\u044e \u0446\u0432\u0435\u0442\u043e\u0432\u0443\u044e \u0441\u0445\u0435\u043c\u0443<\/a> tailwind \u0432 \u0444\u0430\u0439\u043b\u0435 <code>tailwind.config.cjs<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/** @type {import('tailwindcss').Config} *\/ module.exports = {   content: ['.\/src\/**\/*.{js,jsx,ts,tsx}'],   theme: {     extend: {       colors: {         primary: {           50: '#eff6ff',           100: '#dbeafe',           200: '#bfdbfe',           300: '#93c5fd',           400: '#60a5fa',           500: '#3b82f6',           600: '#2563eb',           700: '#1d4ed8',           800: '#1e40af',           900: '#1e3a8a'         }       }     }   },   plugins: [] }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0444\u043e\u0440\u043c\u0443 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>src\/App.tsx<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function App() {   return (     &lt;section className='bg-gray-50'>       &lt;div className='flex flex-col items-center justify-center px-6 py-8 mx-auto md:h-screen lg:py-0'>         &lt;div className='w-full bg-white rounded-lg shadow md:mt-0 sm:max-w-md xl:p-0'>           &lt;div className='p-6 space-y-4 md:space-y-6 sm:p-8'>             &lt;h1 className='title'>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430&lt;\/h1>             &lt;form className='space-y-7'>               &lt;div className='mb-4'>                 &lt;label htmlFor='username' className='label'>                   \u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f *                 &lt;\/label>                 &lt;input                   type='text'                   id='username'                   className='input'                   placeholder='\u0412\u0430\u0448\u0435 \u0438\u043c\u044f'                 \/>               &lt;\/div>               &lt;div className='mb-4'>                 &lt;label htmlFor='age' className='label'>                   \u0412\u043e\u0437\u0440\u0430\u0441\u0442                 &lt;\/label>                 &lt;input                   type='number'                   id='age'                   className='input'                   placeholder='\u041e\u0442 18 \u0434\u043e 65 \u043b\u0435\u0442'                 \/>               &lt;\/div>               &lt;div>                 &lt;label htmlFor='email' className='label'>                   \u0410\u0434\u0440\u0435\u0441 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b *                 &lt;\/label>                 &lt;input                   type='email'                   id='email'                   className='input'                   placeholder='name@mail.com'                 \/>               &lt;\/div>               &lt;div>                 &lt;label htmlFor='password' className='label'>                   \u041f\u0430\u0440\u043e\u043b\u044c *                 &lt;\/label>                 &lt;input                   type='password'                   id='password'                   placeholder='\u041d\u0435 \u043c\u0435\u043d\u0435\u0435 6 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432'                   className='input'                 \/>               &lt;\/div>               &lt;div>                 &lt;label htmlFor='confirmPassword' className='label'>                   \u041f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f *                 &lt;\/label>                 &lt;input                   type='password'                   id='confirmPassword'                   placeholder='\u041d\u0435 \u043c\u0435\u043d\u0435\u0435 6 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432'                   className='input'                 \/>               &lt;\/div>               &lt;div className='flex items-center relative'>                 &lt;input                   id='terms'                   aria-describedby='terms'                   type='checkbox'                   className='w-4 h-4 border border-gray-300 bg-gray-50 accent-primary-500 focus:outline-2 focus:outline-primary-500 outline-none'                 \/>                 &lt;label                   htmlFor='terms'                   className='font-light text-gray-500 text-sm ml-3 cursor-pointer select-none'                 >                   \u042f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e{' '}                   &lt;a                     className='font-medium text-primary-500 hover:text-primary-700 focus:text-primary-700 transition-colors outline-none'                     href='#'                   >                     \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f                   &lt;\/a>                 &lt;\/label>               &lt;\/div>               &lt;div className='flex gap-5 justify-center pt-2'>                 &lt;button                   type='submit'                   className='btn btn-primary'                 >                   \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u043a\u043a\u0430\u0443\u043d\u0442                 &lt;\/button>                 &lt;button                   type='button'                   className='btn btn-error'                 >                   \u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u044f                 &lt;\/button>               &lt;\/div>             &lt;\/form>           &lt;\/div>         &lt;\/div>       &lt;\/div>     &lt;\/section>   ) }  export default App<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/32\/11\/zi\/3211zil9jfkuwsk_88eygaahbkc.png\" data-src=\"https:\/\/habrastorage.org\/webt\/32\/11\/zi\/3211zil9jfkuwsk_88eygaahbkc.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043f\u043e\u043b\u0435\u0439, \u0444\u043e\u0440\u043c\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u044b (&#171;\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u043a\u043a\u0430\u0443\u043d\u0442&#187;) \u0438 \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0435\u0439 (&#171;\u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u044f&#187;). \u041e\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u043e (\u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u043d\u0430 \u043c\u043e\u0439 &#171;\u0432\u043a\u0443\u0441 \u0438 \u0446\u0432\u0435\u0442&#187; ?), \u043d\u043e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e: \u043d\u0430\u0436\u0430\u0442\u0438\u0435 &#171;\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u043a\u043a\u0430\u0443\u043d\u0442&#187; \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2014 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0445\u0435\u043c\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e zod.<\/p>\n<p>  <\/p>\n<h2 id=\"opredelenie-shemy-validacii\">\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0445\u0435\u043c\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/h2>\n<p>  <\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c zod:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">yarn add zod<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u0412\u0430\u0436\u043d\u043e<\/em>: \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b zod \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f TypeScript 4.5+ \u0438 \u0441\u0442\u0440\u043e\u0433\u0438\u0439 \u0440\u0435\u0436\u0438\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"json\">\/\/ tsconfig.json {   \"compilerOptions\": {     \"strict\": true   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0445\u0435\u043c\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e zod \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0445\u0435\u043c\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0430\u043a\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u0430\u043a <a href=\"https:\/\/github.com\/hapijs\/joi\">Joi<\/a>, <a href=\"https:\/\/github.com\/jquense\/yup\">Yup<\/a>, <a href=\"https:\/\/github.com\/gcanti\/io-ts\">io-ts<\/a> \u0438 \u0434\u0440. \u041e\u0434\u043d\u0430\u043a\u043e zod \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0445\u0435\u043c\u044b \u043c\u0435\u043d\u044c\u0448\u0438\u043c\u0438 \u0443\u0441\u0438\u043b\u0438\u044f\u043c\u0438 \u0438 \u043b\u0443\u0447\u0448\u0435 \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u044b \u0434\u0443\u043c\u0430\u0435\u0442\u0435, \u043a\u0430\u043a\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 zod \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438? \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, <a href=\"https:\/\/github.com\/validatorjs\/validator.js\">validator.js<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u0443\u043c\u0430\u0435\u043c \u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u0445 \u043a \u043f\u043e\u043b\u044f\u043c \u0444\u043e\u0440\u043c\u044b. \u041a\u0430\u043a \u043d\u0430\u0441\u0447\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0434\u043b\u0438\u043d\u0430 \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 2 \u0434\u043e 20 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432<\/li>\n<li>\u0432\u043e\u0437\u0440\u0430\u0441\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 18 \u0434\u043e 65 (\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u044d\u0442\u043e \u043f\u043e\u043b\u0435 \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c, \u043d\u043e \u0442\u0430\u043a \u043d\u0435\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e)<\/li>\n<li>email \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c\u2026 email&#8217;\u043e\u043c ?<\/li>\n<li>\u0434\u043b\u0438\u043d\u0430 \u043f\u0430\u0440\u043e\u043b\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 6 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 (\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0431\u0443\u0434\u0443\u0442 \u0431\u043e\u043b\u0435\u0435 \u0436\u0435\u0441\u0442\u043a\u0438\u043c\u0438 \u0432 \u0446\u0435\u043b\u044f\u0445 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u043d\u043e \u043d\u0430\u043c \u0431\u043e\u044f\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0433\u043e)<\/li>\n<li>\u043f\u0430\u0440\u043e\u043b\u0438, \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0432 \u043f\u043e\u043b\u044f\u0445 &#171;\u041f\u0430\u0440\u043e\u043b\u044c&#187; \u0438 &#171;\u041f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f&#187;, \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043e\u0442\u043c\u0435\u0447\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>  <\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u0445\u0435\u043c\u0443 \u0432 <code>App.tsx<\/code> \u043f\u0435\u0440\u0435\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 (\u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 zod):<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">import { z } from 'zod'  const formSchema = z   \/\/ \u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b - \u043e\u0431\u044a\u0435\u043a\u0442   .object({     \/\/ \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f - \u0441\u0442\u0440\u043e\u043a\u0430 (\u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432)     \/\/ https:\/\/github.com\/colinhacks\/zod#primitives     \/\/ https:\/\/github.com\/colinhacks\/zod#strings     username: z       .string()       \/\/ \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432       \/\/ \u0432\u0442\u043e\u0440\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 - \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435       .min(2, { message: '\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0435' })       \/\/ \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432       \/\/ \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435       .max(20, '\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u043e\u0435')       \/\/ \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u043b\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438       \/\/ https:\/\/github.com\/colinhacks\/zod#transform       \/\/ \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043a \u043d\u0438\u0436\u043d\u0435\u043c\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443 \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0430 `_`       .transform((v) => v.toLowerCase().replace(\/\\s+\/g, '_')),     age: z       \/\/ \u0432\u043e\u0437\u0440\u0430\u0441\u0442 - \u0447\u0438\u0441\u043b\u043e       \/\/ https:\/\/github.com\/colinhacks\/zod#numbers       .number()       \/\/ \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u0435 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c       \/\/ .optional()       \/\/ \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u044f       \/\/ https:\/\/github.com\/colinhacks\/zod#refine       .refine((v) => v > 17 &amp;&amp; v &lt; 66, {         message: '\u0412\u043e\u0437\u0440\u0430\u0441\u0442 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430',       }),     email: z.string().email('\u041d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 email'),     password: z.string().min(6, '\u041f\u0430\u0440\u043e\u043b\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439'),     confirmPassword: z.string().min(6, '\u041f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u0435 \u043f\u0430\u0440\u043e\u043b\u044c'),     \/\/ \u043e\u0441\u043e\u0431\u044b\u0439 \u0442\u0438\u043f - \u043b\u0438\u0442\u0435\u0440\u0430\u043b, \u043c\u043e\u0436\u0435\u0442 (\u0434\u043e\u043b\u0436\u0435\u043d) \u0438\u043c\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435     terms: z.literal(true, {       \/\/ \u043e\u0448\u0438\u0431\u043a\u0438 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0430\u0440\u0442 \u043e\u0448\u0438\u0431\u043e\u043a       \/\/ https:\/\/github.com\/colinhacks\/zod\/blob\/master\/ERROR_HANDLING.md#customizing-errors-with-zoderrormap       errorMap: () => ({ message: '\u041f\u0440\u0438\u043c\u0438\u0442\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f' }),     }),   })   \/\/ \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0444\u043e\u0440\u043c\u044b - \u0432\u0441\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430   .refine((data) => data.password === data.confirmPassword, {     \/\/ \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u044c - \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439     \/\/ https:\/\/github.com\/colinhacks\/zod#customize-error-path     path: ['confirmPassword'],     message: '\u0412\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u043e\u043b\u0438 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442',   })<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d\u0430, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430), \u043d\u043e \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0442\u0438\u043f\u044b \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043b\u0435\u0433\u043a\u0438\u043c \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435\u043c \u0440\u0443\u043a\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">type FormSchema = z.infer&lt;typeof formSchema><\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441: \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u0441\u0445\u0435\u043c\u0443 \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b? \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0444\u043e\u0440\u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f react-hook-form (\u0434\u0430\u043b\u0435\u0435 \u2014 RHF), \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u0432\u0435\u0441\u0442\u0438 \u043a \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 zod \u0438 RHF. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 RHF.<\/p>\n<p>  <\/p>\n<h2 id=\"obrabotka-formy\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0444\u043e\u0440\u043c\u044b<\/h2>\n<p>  <\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c RHF:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">yarn add react-hook-form<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0445\u0443\u043a\u043e\u043c RHF \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/react-hook-form.com\/api\/useform\/\">useForm()<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u043f\u043e\u0432 (\u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445, \u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0437\u0436\u0435). \u041e\u043d \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u0435\u0439 \u0444\u043e\u0440\u043c\u044b, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f <a href=\"https:\/\/ru.reactjs.org\/docs\/uncontrolled-components.html\">\u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c\u0438 (uncontrolled)<\/a> (\u043a \u0441\u043b\u043e\u0432\u0443, \u0432 <a href=\"https:\/\/beta.reactjs.org\/reference\/react-dom\/components\/input\">\u043d\u043e\u0432\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 React<\/a> \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u0438\u043d\u043f\u0443\u0442\u043e\u0432).<\/p>\n<p>  <\/p>\n<p><code>useForm()<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/react-hook-form.com\/api\/useform\/register\/\">register<\/a> \u2014 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b<\/li>\n<li><a href=\"https:\/\/react-hook-form.com\/api\/useform\/handlesubmit\/\">handleSubmit<\/a> \u2014 \u043c\u0435\u0442\u043e\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u044b<\/li>\n<li><a href=\"https:\/\/react-hook-form.com\/api\/useform\/reset\/\">reset<\/a> \u2014 \u043c\u0435\u0442\u043e\u0434 \u0441\u0431\u0440\u043e\u0441\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u044b (\u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0435\u0439)<\/li>\n<li><a href=\"https:\/\/react-hook-form.com\/api\/useform\/setfocus\/\">setFocus<\/a> \u2014 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0444\u043e\u043a\u0443\u0441\u0430 \u043d\u0430 \u043f\u043e\u043b\u0435<\/li>\n<li><a href=\"https:\/\/react-hook-form.com\/api\/useform\/formstate\/\">formState<\/a> \u2014 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u044b<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e, \u0442\u043e \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>isDirty<\/code> \u2014 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>true<\/code> \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043b\u044e\u0431\u043e\u0433\u043e \u043f\u043e\u043b\u044f<\/li>\n<li><code>isSubmitting<\/code> \u2014 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>true<\/code> \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u044b<\/li>\n<li><code>errors<\/code> \u2014 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u043f\u043e\u043b\u0435\u0439<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0420\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c <code>App.tsx<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">import { SubmitHandler, useForm } from 'react-hook-form'  \/\/ \u0421\u0445\u0435\u043c\u0430  type FormSchema = z.infer&lt;typeof formSchema>  function App() {   const {     register,     handleSubmit,     reset,     setFocus,     formState: { isDirty, isSubmitting, errors },   } = useForm&lt;FormSchema>()    \/\/ \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u044b   const onSubmit: SubmitHandler&lt;FormSchema> = (data) => {     \/\/ \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c     console.log(data)     \/\/ \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b (\u043e\u0447\u0438\u0449\u0430\u0435\u043c \u043f\u043e\u043b\u044f)     reset()   }    useEffect(() => {     \/\/ \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0444\u043e\u043a\u0443\u0441 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 (\u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f) \u043f\u043e\u0441\u043b\u0435 \u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430     setFocus('username')   }, [])    \/\/ ... }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u044b, \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b, \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0438 (\u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0438 \u0434\u043e \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u0444\u043e\u0440\u043c\u043e\u0439 \u0438 \u043d\u0430 \u043f\u0435\u0440\u0438\u043e\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">{\/* \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u044b *\/} &lt;form className='space-y-7' onSubmit={handleSubmit(onSubmit)}>   &lt;div className='mb-4'>     &lt;label htmlFor='username' className='label'>       \u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f *     &lt;\/label>     &lt;input       {\/* \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u043b\u0435 \u0444\u043e\u0440\u043c\u044b *\/}       {\/* \u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 `register()`, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0438\u043d\u043f\u0443\u0442\u0443 \u043f\u0440\u043e\u043f\u044b `onChange`, `onBlur`, `ref` \u0438 `name` *\/}       {...register('username')}       type='text'       id='username'       className='input'       placeholder='\u0412\u0430\u0448\u0435 \u0438\u043c\u044f'       \/\/ \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438       aria-invalid={errors.username ? 'true' : 'false'}     \/>     {\/* \u0420\u0435\u043d\u0434\u0435\u0440\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 *\/}     {errors.username &amp;&amp; (       &lt;span role='alert' className='error'>         {errors.username?.message}       &lt;\/span>     )}   &lt;\/div>   &lt;div className='mb-4'>     &lt;label htmlFor='age' className='label'>       \u0412\u043e\u0437\u0440\u0430\u0441\u0442     &lt;\/label>     &lt;input       {...register('age', {         \/\/ \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 (\u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 `type=\"number\"`),         \/\/ \u0430 \u0434\u043b\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u043e         setValueAs: (v) => Number(v),       })}       type='number'       id='age'       className='input'       placeholder='\u041e\u0442 18 \u0434\u043e 65 \u043b\u0435\u0442'       aria-invalid={errors.age ? 'true' : 'false'}     \/>     {errors.age &amp;&amp; (       &lt;span role='alert' className='error'>         {errors.age?.message}       &lt;\/span>     )}   &lt;\/div>   &lt;div>     &lt;label htmlFor='email' className='label'>       \u0410\u0434\u0440\u0435\u0441 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b *     &lt;\/label>     &lt;input       {...register('email')}       type='email'       id='email'       className='input'       placeholder='name@mail.com'       aria-invalid={errors.email ? 'true' : 'false'}     \/>     {errors.email &amp;&amp; (       &lt;span role='alert' className='error'>         {errors.email?.message}       &lt;\/span>     )}   &lt;\/div>   &lt;div>     &lt;label htmlFor='password' className='label'>       \u041f\u0430\u0440\u043e\u043b\u044c *     &lt;\/label>     &lt;input       {...register('password')}       type='password'       id='password'       placeholder='\u041d\u0435 \u043c\u0435\u043d\u0435\u0435 6 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432'       className='input'       aria-invalid={errors.password ? 'true' : 'false'}     \/>     {errors.password &amp;&amp; (       &lt;span role='alert' className='error'>         {errors.password?.message}       &lt;\/span>     )}   &lt;\/div>   &lt;div>     &lt;label htmlFor='confirmPassword' className='label'>       \u041f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f *     &lt;\/label>     &lt;input       {...register('confirmPassword')}       type='password'       id='confirmPassword'       placeholder='\u041d\u0435 \u043c\u0435\u043d\u0435\u0435 6 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432'       className='input'       aria-invalid={errors.confirmPassword ? 'true' : 'false'}     \/>     {errors.confirmPassword &amp;&amp; (       &lt;span role='alert' className='error'>         {errors.confirmPassword?.message}       &lt;\/span>     )}   &lt;\/div>   &lt;div className='flex items-center relative'>     &lt;input       {...register('terms')}       id='terms'       aria-describedby='terms'       type='checkbox'       className='w-4 h-4 border border-gray-300 bg-gray-50 accent-primary-500 focus:outline-2 focus:outline-primary-500 outline-none'       aria-invalid={errors.terms ? 'true' : 'false'}     \/>     &lt;label       htmlFor='terms'       className='font-light text-gray-500 text-sm ml-3 cursor-pointer select-none'     >       \u042f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e{' '}       &lt;a         className='font-medium text-primary-500 hover:text-primary-700 focus:text-primary-700 transition-colors outline-none'         href='#'       >         \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f       &lt;\/a>     &lt;\/label>     {errors.terms &amp;&amp; (       &lt;span className='error top-5'>{errors.terms?.message}&lt;\/span>     )}   &lt;\/div>   &lt;div className='flex gap-5 justify-center pt-2'>     &lt;button       type='submit'       className='btn btn-primary'       \/\/ \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0443       disabled={!isDirty || isSubmitting}     >       \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u043a\u043a\u0430\u0443\u043d\u0442     &lt;\/button>     &lt;button       type='button'       className='btn btn-error'       disabled={!isDirty || isSubmitting}       \/\/ \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u044d\u0442\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0441\u0431\u0440\u043e\u0441\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u044b       \/\/ \u0442\u0438\u043f\u044b `onClick()` \u0438 `reset()` \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b,       \/\/ \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c `onClick={reset}`       onClick={() => reset()}     >       \u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u044f     &lt;\/button>   &lt;\/div> &lt;\/form><\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043b\u0438 \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b, \u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0444\u043e\u0440\u043c\u044b (\u0434\u043b\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f) \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u043f\u0440\u0435\u0436\u043d\u0438\u043c, \u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u044b \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043a\u043d\u043e\u043f\u043e\u043a. \u041f\u043e\u0447\u0435\u043c\u0443? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u0435\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c.<\/p>\n<p>  <\/p>\n<p>\u0421\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e\u0441\u0442\u0438 \u0440\u0430\u0434\u0438, \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e RHF, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0448\u0438\u0440\u043e\u043a\u0438\u0435 <a href=\"https:\/\/react-hook-form.com\/get-started#Applyvalidation\">\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/a> \u043f\u043e\u043b\u0435\u0439 \u0444\u043e\u0440\u043c\u044b, \u043d\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e ?<\/p>\n<p>  <\/p>\n<h2 id=\"integraciya-zod-i-rect-hook-form-i-proverka-validacii\">\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f Zod \u0438 Rect Hook Form \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/h2>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043f\u0440\u043e\u043f\u043e\u0432, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c\u044b\u0445 <code>useForm()<\/code>, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u043f <a href=\"https:\/\/react-hook-form.com\/api\/useform\/#resolver\">resolver<\/a>, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f RHF \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e &#171;\u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440\u043e\u0432&#187; \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 <a href=\"https:\/\/github.com\/react-hook-form\/resolvers\">@hookform\/resolvers<\/a>. \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">yarn add @hookform\/resolvers<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>zodResolver<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">import { zodResolver } from '@hookform\/resolvers\/zod'<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0445\u0435\u043c\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">zodResolver(formSchema)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 zod \u0438 RHF \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>useForm()<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">useForm&lt;FormSchema>({ resolver: zodResolver(formSchema) })<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0444\u043e\u0440\u043c\u044b<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import { z } from 'zod' import { SubmitHandler, useForm } from 'react-hook-form' import { zodResolver } from '@hookform\/resolvers\/zod' import { useEffect } from 'react'  const formSchema = z   .object({     username: z       .string()       .min(2, { message: '\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0435' })       .max(20, '\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u043e\u0435')       .transform((v) => v.toLowerCase().replace(\/\\s+\/g, '_')),     age: z       .number()       \/\/ .optional()       .refine((v) => v > 17 &amp;&amp; v &lt; 66, {         message: '\u0412\u043e\u0437\u0440\u0430\u0441\u0442 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430',       }),     email: z.string().email('\u041d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 email'),     password: z.string().min(6, '\u041f\u0430\u0440\u043e\u043b\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439'),     confirmPassword: z.string().min(6, '\u041f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u0435 \u043f\u0430\u0440\u043e\u043b\u044c'),     terms: z.literal(true, {       errorMap: () => ({ message: '\u041f\u0440\u0438\u043c\u0438\u0442\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f' }),     }),   })   .refine((data) => data.password === data.confirmPassword, {     path: ['confirmPassword'],     message: '\u0412\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u043e\u043b\u0438 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442',   })  type FormSchema = z.infer&lt;typeof formSchema>  function App() {   const {     register,     handleSubmit,     reset,     setFocus,     formState: { isDirty, isSubmitting, errors },   } = useForm&lt;FormSchema>({ resolver: zodResolver(formSchema) })    const onSubmit: SubmitHandler&lt;FormSchema> = (data) => {     console.log(data)     reset()   }    useEffect(() => {     setFocus('username')   }, [])    return (     &lt;section className='bg-gray-50'>       &lt;div className='flex flex-col items-center justify-center px-6 py-8 mx-auto md:h-screen lg:py-0'>         &lt;div className='w-full bg-white rounded-lg shadow md:mt-0 sm:max-w-md xl:p-0'>           &lt;div className='p-6 space-y-4 md:space-y-6 sm:p-8'>             &lt;h1 className='title'>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430&lt;\/h1>             &lt;form className='space-y-7' onSubmit={handleSubmit(onSubmit)}>               &lt;div className='mb-4'>                 &lt;label htmlFor='username' className='label'>                   \u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f *                 &lt;\/label>                 &lt;input                   {...register('username')}                   type='text'                   id='username'                   className='input'                   placeholder='\u0412\u0430\u0448\u0435 \u0438\u043c\u044f'                   aria-invalid={errors.username ? 'true' : 'false'}                 \/>                 {errors.username &amp;&amp; (                   &lt;span role='alert' className='error'>                     {errors.username?.message}                   &lt;\/span>                 )}               &lt;\/div>               &lt;div className='mb-4'>                 &lt;label htmlFor='age' className='label'>                   \u0412\u043e\u0437\u0440\u0430\u0441\u0442                 &lt;\/label>                 &lt;input                   {...register('age', {                     setValueAs: (v) => Number(v),                   })}                   type='number'                   id='age'                   className='input'                   placeholder='\u041e\u0442 18 \u0434\u043e 65 \u043b\u0435\u0442'                   aria-invalid={errors.age ? 'true' : 'false'}                 \/>                 {errors.age &amp;&amp; (                   &lt;span role='alert' className='error'>                     {errors.age?.message}                   &lt;\/span>                 )}               &lt;\/div>               &lt;div>                 &lt;label htmlFor='email' className='label'>                   \u0410\u0434\u0440\u0435\u0441 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b *                 &lt;\/label>                 &lt;input                   {...register('email')}                   type='email'                   id='email'                   className='input'                   placeholder='name@mail.com'                   aria-invalid={errors.email ? 'true' : 'false'}                 \/>                 {errors.email &amp;&amp; (                   &lt;span role='alert' className='error'>                     {errors.email?.message}                   &lt;\/span>                 )}               &lt;\/div>               &lt;div>                 &lt;label htmlFor='password' className='label'>                   \u041f\u0430\u0440\u043e\u043b\u044c *                 &lt;\/label>                 &lt;input                   {...register('password')}                   type='password'                   id='password'                   placeholder='\u041d\u0435 \u043c\u0435\u043d\u0435\u0435 6 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432'                   className='input'                   aria-invalid={errors.password ? 'true' : 'false'}                 \/>                 {errors.password &amp;&amp; (                   &lt;span role='alert' className='error'>                     {errors.password?.message}                   &lt;\/span>                 )}               &lt;\/div>               &lt;div>                 &lt;label htmlFor='confirmPassword' className='label'>                   \u041f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f *                 &lt;\/label>                 &lt;input                   {...register('confirmPassword')}                   type='password'                   id='confirmPassword'                   placeholder='\u041d\u0435 \u043c\u0435\u043d\u0435\u0435 6 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432'                   className='input'                   aria-invalid={errors.confirmPassword ? 'true' : 'false'}                 \/>                 {errors.confirmPassword &amp;&amp; (                   &lt;span role='alert' className='error'>                     {errors.confirmPassword?.message}                   &lt;\/span>                 )}               &lt;\/div>               &lt;div className='flex items-center relative'>                 &lt;input                   {...register('terms')}                   id='terms'                   aria-describedby='terms'                   type='checkbox'                   className='w-4 h-4 border border-gray-300 bg-gray-50 accent-primary-500 focus:outline-2 focus:outline-primary-500 outline-none'                   aria-invalid={errors.terms ? 'true' : 'false'}                 \/>                 &lt;label                   htmlFor='terms'                   className='font-light text-gray-500 text-sm ml-3 cursor-pointer select-none'                 >                   \u042f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e{' '}                   &lt;a                     className='font-medium text-primary-500 hover:text-primary-700 focus:text-primary-700 transition-colors outline-none'                     href='#'                   >                     \u0423\u0441\u043b\u043e\u0432\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f                   &lt;\/a>                 &lt;\/label>                 {errors.terms &amp;&amp; (                   &lt;span className='error top-5'>{errors.terms?.message}&lt;\/span>                 )}               &lt;\/div>               &lt;div className='flex gap-5 justify-center pt-2'>                 &lt;button                   type='submit'                   className='btn btn-primary'                   disabled={!isDirty || isSubmitting}                 >                   \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u043a\u043a\u0430\u0443\u043d\u0442                 &lt;\/button>                 &lt;button                   type='button'                   className='btn btn-error'                   disabled={!isDirty || isSubmitting}                   onClick={() => reset()}                 >                   \u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u043b\u044f                 &lt;\/button>               &lt;\/div>             &lt;\/form>           &lt;\/div>         &lt;\/div>       &lt;\/div>     &lt;\/section>   ) }  export default App<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0443:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/tv\/gx\/bt\/tvgxbtho6xilrxpg3qiejeuwv2y.png\" data-src=\"https:\/\/habrastorage.org\/webt\/tv\/gx\/bt\/tvgxbtho6xilrxpg3qiejeuwv2y.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0432\u0432\u0435\u0434\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c):<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/dm\/51\/5p\/dm515pgz1dj1qul5i_r9crwyev4.png\" data-src=\"https:\/\/habrastorage.org\/webt\/dm\/51\/5p\/dm515pgz1dj1qul5i_r9crwyev4.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043d\u0430\u0448\u0438\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/v8\/yq\/d2\/v8yqd22rb1dzipcj_v87otrn7fg.png\" data-src=\"https:\/\/habrastorage.org\/webt\/v8\/yq\/d2\/v8yqd22rb1dzipcj_v87otrn7fg.png\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u0414\u0435\u043c\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<div class=\"oembed\"><a href=\"https:\/\/codesandbox.io\/p\/sandbox\/react-hook-form-zod-sp9wx8\">https:\/\/codesandbox.io\/p\/sandbox\/react-hook-form-zod-sp9wx8<\/a><\/div>\n<p>  <\/p>\n<p>\u0418\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043b\u0438 \u043d\u0430\u0441 \u0442\u0430\u043a\u0430\u044f \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435? \u041d\u0435\u0442. \u041f\u043e\u0447\u0435\u043c\u0443? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044f \u043c\u043e\u0433\u0443 \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c JavaScript, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>action<\/code> \u0441 \u0430\u0434\u0440\u0435\u0441\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>\/api\/auth\/register<\/code> \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0435\u0441\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0443\u0441\u0442\u0443\u044e \u0444\u043e\u0440\u043c\u0443 (\u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>disabled<\/code> \u043a\u043d\u043e\u043f\u043a\u0438 &#171;\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u043a\u043a\u0430\u0443\u043d\u0442&#187; \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">http:\/\/localhost:5173\/api\/auth\/register?username=&amp;age=&amp;email=&amp;password=&amp;confirmPassword=<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0441\u0445\u0435\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438? \u042d\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u043d\u043e\u0433\u0438\u0445 \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u0432. \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 zod \u0438 RHF. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u043b\u0430\u0434\u0435\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u043c\u043e\u0436\u043d\u043e \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043a\u0443\u0447\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0444\u043e\u0440\u043c. \u0422\u0430\u043a \u0447\u0442\u043e \u0440\u0435\u0448\u0430\u0439\u0442\u0435 \u0441\u0430\u043c\u0438: \u0438\u043d\u0432\u0435\u0441\u0442\u0438\u0446\u0438\u0438 \u0432 \u0441\u0435\u0431\u044f (\u0447\u0435\u043c, \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439) \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u043f\u0440\u0430\u0432\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f ?<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u044b \u0443\u0437\u043d\u0430\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0435 \u0438 \u043d\u0435 \u0437\u0440\u044f \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<p>  <\/p>\n<p>Happy coding!<\/p>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<p><a href=\"https:\/\/timeweb.cloud\/vds-vps?utm_source=habr&amp;utm_medium=banner&amp;utm_campaign\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/mx\/ua\/nb\/mxuanbovcusqgmqdgugvpnql8vq.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/mx\/ua\/nb\/mxuanbovcusqgmqdgugvpnql8vq.jpeg\" data-blurred=\"true\"\/><\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/timeweb\/blog\/722108\/\"> https:\/\/habr.com\/ru\/company\/timeweb\/blog\/722108\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/jc\/hw\/st\/jchwst6a3nwlxlscnmuw5tdhmry.png\" data-src=\"https:\/\/habrastorage.org\/webt\/jc\/hw\/st\/jchwst6a3nwlxlscnmuw5tdhmry.png\"\/>  <\/p>\n<p>  Hello, world!<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0441\u0445\u0435\u043c\u0435 (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0435 \u0442\u0430\u043a) \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438 \u0432 <a href=\"https:\/\/ru.reactjs.org\/\">React<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043c\u043d\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439. \u042d\u0442\u0430 \u0441\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <a href=\"https:\/\/react-hook-form.com\/\">React Hook Form<\/a> \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0444\u043e\u0440\u043c \u0438 <a href=\"https:\/\/github.com\/colinhacks\/zod\">Zod<\/a> \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0445\u0435\u043c\u044b \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0440\u0443\u0433\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0438\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u0413\u043b\u0430\u0432\u043d\u044b\u043c\u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 (type inference).<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0434, \u0432\u043e\u0442 <a href=\"https:\/\/github.com\/harryheman\/Blog-Posts\/tree\/master\/react-hook-form-zod\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e? \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0448\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-347048","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347048","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=347048"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347048\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}