{"id":46,"date":"2024-12-18T08:02:33","date_gmt":"2024-12-18T08:02:33","guid":{"rendered":"https:\/\/fullstacknotes.netblocs.com\/?p=46"},"modified":"2024-12-18T09:58:38","modified_gmt":"2024-12-18T09:58:38","slug":"must-know-react-libraries-formik-and-yup","status":"publish","type":"post","link":"https:\/\/netblocs.com\/fullstacknotes\/must-know-react-libraries-formik-and-yup\/","title":{"rendered":"Must-Know React Libraries  Formik and Yup"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"506\" src=\"https:\/\/fullstacknotes.netblocs.com\/wp-content\/uploads\/2024\/12\/react-js-egitimi.png\" alt=\"\" class=\"wp-image-100\" style=\"width:400px\" srcset=\"https:\/\/netblocs.com\/fullstacknotes\/wp-content\/uploads\/2024\/12\/react-js-egitimi.png 900w, https:\/\/netblocs.com\/fullstacknotes\/wp-content\/uploads\/2024\/12\/react-js-egitimi-300x169.png 300w, https:\/\/netblocs.com\/fullstacknotes\/wp-content\/uploads\/2024\/12\/react-js-egitimi-768x432.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">What are Formik and Yup?<\/h3>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">What is Formik?<\/h3>\n\n\n\n<p>Formik is a library that simplifies the management of form components. It is used to manage user inputs, error messages, and the overall form state (e.g., whether it has been submitted or is valid). Formik automatically tracks and controls the form&#8217;s state and validity.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">What is Yup?<\/h3>\n\n\n\n<p>Yup is a schema validation library for JavaScript. When used with Formik, it can be used to validate user inputs. With Yup, you can define which fields are required, how to validate certain formats, and more.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Simple Example<\/h3>\n\n\n\n<p>Below, we will create a simple form using Formik and Yup. The form will have an&nbsp;<code>email<\/code>&nbsp;and a&nbsp;<code>password<\/code>&nbsp;field, and these fields will be subject to validation rules.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Installing the Required Packages<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#232136\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"npm install formik yup\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E0DEF4; font-style: italic\">npm<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">install<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">formik<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">yup<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Example Code<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#232136\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\nimport React from 'react';\nimport { Formik, Form, Field, ErrorMessage } from 'formik';\nimport * as Yup from 'yup';\n\nconst MyForm = () =&gt; {\n  const validationSchema = Yup.object().shape({\n    email: Yup.string()\n      .email('Invalid email address')\n      .required('Email is required'),\n    password: Yup.string()\n      .min(6, 'Password must be at least 6 characters')\n      .required('Password is required'),\n  });\n\n  return (\n    &lt;Formik\n      initialValues={{ email: '', password: '' }}\n      validationSchema={validationSchema}\n      onSubmit={(values) =&gt; {\n        console.log('Form values:', values);\n      }}\n    &gt;\n      {() =&gt; (\n        &lt;Form&gt;\n          &lt;div&gt;\n            &lt;label htmlFor=&quot;email&quot;&gt;Email:&lt;\/label&gt;\n            &lt;Field name=&quot;email&quot; type=&quot;email&quot; \/&gt;\n            &lt;ErrorMessage name=&quot;email&quot; component=&quot;div&quot; \/&gt;\n          &lt;\/div&gt;\n\n          &lt;div&gt;\n            &lt;label htmlFor=&quot;password&quot;&gt;Password:&lt;\/label&gt;\n            &lt;Field name=&quot;password&quot; type=&quot;password&quot; \/&gt;\n            &lt;ErrorMessage name=&quot;password&quot; component=&quot;div&quot; \/&gt;\n          &lt;\/div&gt;\n\n          &lt;button type=&quot;submit&quot;&gt;Submit&lt;\/button&gt;\n        &lt;\/Form&gt;\n      )}\n    &lt;\/Formik&gt;\n};\n\nexport default MyForm;\n\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #E0DEF4; font-style: italic\">React<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&#39;react&#39;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">Formik<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">Form<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">Field<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">ErrorMessage<\/span><span style=\"color: #3E8FB0\"> <\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&#39;formik&#39;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import <\/span><span style=\"color: #EA9A97\">*<\/span><span style=\"color: #3E8FB0\"> as <\/span><span style=\"color: #E0DEF4; font-style: italic\">Yup<\/span><span style=\"color: #3E8FB0\"> from <\/span><span style=\"color: #F6C177\">&#39;yup&#39;<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">const<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97; font-style: italic\">MyForm<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">()<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=&gt;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #3E8FB0\">const<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">validationSchema<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">Yup<\/span><span style=\"color: #3E8FB0\">.<\/span><span style=\"color: #EA9A97\">object<\/span><span style=\"color: #E0DEF4\">()<\/span><span style=\"color: #3E8FB0\">.<\/span><span style=\"color: #EA9A97\">shape<\/span><span style=\"color: #E0DEF4\">(<\/span><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    email<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">Yup<\/span><span style=\"color: #3E8FB0\">.<\/span><span style=\"color: #EA9A97\">string<\/span><span style=\"color: #E0DEF4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #3E8FB0\">.<\/span><span style=\"color: #EA9A97\">email<\/span><span style=\"color: #E0DEF4\">(<\/span><span style=\"color: #F6C177\">&#39;Invalid email address&#39;<\/span><span style=\"color: #E0DEF4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #3E8FB0\">.<\/span><span style=\"color: #EA9A97\">required<\/span><span style=\"color: #E0DEF4\">(<\/span><span style=\"color: #F6C177\">&#39;Email is required&#39;<\/span><span style=\"color: #E0DEF4\">)<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    password<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">Yup<\/span><span style=\"color: #3E8FB0\">.<\/span><span style=\"color: #EA9A97\">string<\/span><span style=\"color: #E0DEF4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #3E8FB0\">.<\/span><span style=\"color: #EA9A97\">min<\/span><span style=\"color: #E0DEF4\">(<\/span><span style=\"color: #EA9A97\">6<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&#39;Password must be at least 6 characters&#39;<\/span><span style=\"color: #E0DEF4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #3E8FB0\">.<\/span><span style=\"color: #EA9A97\">required<\/span><span style=\"color: #E0DEF4\">(<\/span><span style=\"color: #F6C177\">&#39;Password is required&#39;<\/span><span style=\"color: #E0DEF4\">)<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA\">}<\/span><span style=\"color: #E0DEF4\">)<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #3E8FB0\">return<\/span><span style=\"color: #E0DEF4\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">Formik<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #C4A7E7; font-style: italic\">initialValues<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #908CAA\">{{<\/span><span style=\"color: #E0DEF4\"> email<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&#39;&#39;<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> password<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&#39;&#39;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">}}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #C4A7E7; font-style: italic\">validationSchema<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #E0DEF4; font-style: italic\">validationSchema<\/span><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #C4A7E7; font-style: italic\">onSubmit<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #908CAA\">{(<\/span><span style=\"color: #C4A7E7; font-style: italic\">values<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=&gt;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #E0DEF4; font-style: italic\">console<\/span><span style=\"color: #3E8FB0\">.<\/span><span style=\"color: #EA9A97\">log<\/span><span style=\"color: #E0DEF4\">(<\/span><span style=\"color: #F6C177\">&#39;Form values:&#39;<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">values<\/span><span style=\"color: #E0DEF4\">)<\/span><span style=\"color: #908CAA\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #908CAA\">}}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><span style=\"color: #908CAA\">{()<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=&gt;<\/span><span style=\"color: #E0DEF4\"> (<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">Form<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">          <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">div<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">label<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">htmlFor<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;email&quot;<\/span><span style=\"color: #6E6A86\">&gt;<\/span><span style=\"color: #E0DEF4\">Email:<\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">label<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">Field<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">name<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;email&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">type<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;email&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #6E6A86\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">ErrorMessage<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">name<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;email&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">component<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;div&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #6E6A86\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">          <\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">div<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">          <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">div<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">label<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">htmlFor<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;password&quot;<\/span><span style=\"color: #6E6A86\">&gt;<\/span><span style=\"color: #E0DEF4\">Password:<\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">label<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">Field<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">name<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;password&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">type<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;password&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #6E6A86\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">ErrorMessage<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">name<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;password&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">component<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;div&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #6E6A86\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">          <\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">div<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">          <\/span><span style=\"color: #6E6A86\">&lt;<\/span><span style=\"color: #9CCFD8\">button<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">type<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #F6C177\">&quot;submit&quot;<\/span><span style=\"color: #6E6A86\">&gt;<\/span><span style=\"color: #E0DEF4\">Submit<\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">button<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">Form<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      )<\/span><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #6E6A86\">&lt;\/<\/span><span style=\"color: #9CCFD8\">Formik<\/span><span style=\"color: #6E6A86\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4; font-style: italic\">export<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">default<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #E0DEF4; font-style: italic\">MyForm<\/span><span style=\"color: #E0DEF4\">;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Importing Formik and Yup<\/strong>: We import the Formik and Yup libraries.<\/li>\n\n\n\n<li><strong>Validation Schema<\/strong>: We define a&nbsp;<code>validationSchema<\/code>&nbsp;using Yup. For the&nbsp;<code>email<\/code>&nbsp;field, we specify a valid email format, and for the&nbsp;<code>password<\/code>&nbsp;field, we require a minimum of 6 characters.<\/li>\n\n\n\n<li><strong>Using Formik<\/strong>: We create the form using the Formik component. The&nbsp;<code>initialValues<\/code>&nbsp;prop is used to define the initial values of the form fields.<\/li>\n\n\n\n<li><strong>Field and ErrorMessage<\/strong>: We define the form fields and error messages. The&nbsp;<code>Field<\/code>&nbsp;component represents the form fields, while the&nbsp;<code>ErrorMessage<\/code>&nbsp;component is used to display validation error messages.<\/li>\n\n\n\n<li><strong>Submit Handler<\/strong>: When the form is submitted, the&nbsp;<code>onSubmit<\/code>&nbsp;function is triggered and logs the form values to the console.<\/li>\n<\/ol>\n\n\n\n<p>This example demonstrates the basics of creating a simple form using Formik and Yup. You can add more fields and extend the validation rules to suit your needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What are Formik and Yup? What is Formik? Formik is a library that simplifies the management of form components. It is used to manage user inputs, error messages, and the&hellip;<\/p>\n","protected":false},"author":1,"featured_media":48,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,11,21],"tags":[25,15,14,19,26],"class_list":["post-46","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-libraries","category-react","category-react-libraries","tag-formik","tag-libraries","tag-react","tag-react-libraries","tag-yup"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":3,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":108,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/posts\/46\/revisions\/108"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/media\/48"}],"wp:attachment":[{"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netblocs.com\/fullstacknotes\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}