<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shivani R</title>
    <description>The latest articles on DEV Community by Shivani R (@shivani_ravikumar).</description>
    <link>https://dev.to/shivani_ravikumar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3921111%2F755ea8ee-5f25-4f0c-984c-f52df1a29ae7.png</url>
      <title>DEV Community: Shivani R</title>
      <link>https://dev.to/shivani_ravikumar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shivani_ravikumar"/>
    <language>en</language>
    <item>
      <title>Why Formik `isValid` Doesn’t Update Correctly in Multi-Step Forms (And the Fix That Worked for Me)</title>
      <dc:creator>Shivani R</dc:creator>
      <pubDate>Sat, 09 May 2026 06:13:21 +0000</pubDate>
      <link>https://dev.to/shivani_ravikumar/why-formik-isvalid-doesnt-update-correctly-in-multi-step-forms-and-the-fix-that-worked-for-me-lp3</link>
      <guid>https://dev.to/shivani_ravikumar/why-formik-isvalid-doesnt-update-correctly-in-multi-step-forms-and-the-fix-that-worked-for-me-lp3</guid>
      <description>&lt;p&gt;While building a multi-step form using React + Formik, I ran into a frustrating issue:&lt;/p&gt;

&lt;p&gt;👉 The &lt;code&gt;Next&lt;/code&gt; button stayed enabled even after moving to a new step with empty required fields.&lt;/p&gt;

&lt;p&gt;At first, everything looked correct:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Separate validation schema per step&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;isValid&lt;/code&gt; used to disable navigation&lt;/li&gt;
&lt;li&gt;Dynamic step rendering&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But Formik validation state wasn’t updating properly when the step changed.&lt;/p&gt;

&lt;p&gt;Here’s what was happening — and the solution that finally worked.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 The Problem
&lt;/h2&gt;

&lt;p&gt;I had a setup like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Formik&lt;/span&gt;
  &lt;span class="na"&gt;initialValues&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;initialValues&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;validationSchema&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;multiPageFormsValidationSchema&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;currentStep&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  // form logic
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Formik&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each step had its own validation schema.&lt;/p&gt;

&lt;p&gt;The issue:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 1 becomes valid → &lt;code&gt;isValid = true&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Move to Step 2&lt;/li&gt;
&lt;li&gt;New fields are empty&lt;/li&gt;
&lt;li&gt;❌ &lt;code&gt;isValid&lt;/code&gt; still remains &lt;code&gt;true&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This caused the &lt;code&gt;Next&lt;/code&gt; button to stay enabled incorrectly. But it would get disabled if its clicked with empty fields.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Why This Happens
&lt;/h2&gt;

&lt;p&gt;Formik does not automatically re-run validation properly when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the validation schema changes dynamically&lt;/li&gt;
&lt;li&gt;the form step changes&lt;/li&gt;
&lt;li&gt;fields are conditionally rendered&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So even though the schema changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;validationSchema&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;multiPageFormsValidationSchema&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;currentStep&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Formik continues using stale validation state until another user interaction happens.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔥 The Solution That Worked for Me
&lt;/h2&gt;

&lt;p&gt;What finally fixed it was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;formik&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useFormik&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
   &lt;span class="nx"&gt;initialValues&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;values&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
   &lt;span class="na"&gt;validationSchema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;multiPageFormsValidationSchema&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;currentStep&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;values&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;resetForm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;validateForm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isValid&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;formik&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;checkFormValidation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;resetForm&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;values&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;validateForm&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="nf"&gt;checkFormValidation&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;currentStep&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;FormikProvider&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;formik&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Form&lt;/span&gt; &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    // form logic
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;FormikProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ✅ Why This Works
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;resetForm({ values })&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This forces Formik to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reset Formik’s internal state while preserving the current form values&lt;/li&gt;
&lt;li&gt;reinitialize touched/errors state correctly&lt;/li&gt;
&lt;li&gt;acknowledge the new schema properly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without this, Formik sometimes keeps stale validation metadata from the previous step.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;code&gt;validateForm()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This immediately re-runs validation for the current step schema.&lt;/p&gt;

&lt;p&gt;So when the step changes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;new fields get validated instantly&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;isValid&lt;/code&gt; updates correctly&lt;/li&gt;
&lt;li&gt;navigation buttons behave properly&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Why I Used useFormik + FormikProvider Instead of the  Component
&lt;/h3&gt;

&lt;p&gt;This gave me more control over the form instance and validation lifecycle.&lt;/p&gt;

&lt;p&gt;Since my form behavior depended heavily on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dynamic step changes&lt;/li&gt;
&lt;li&gt;manually triggering validation&lt;/li&gt;
&lt;li&gt;resetting form state&lt;/li&gt;
&lt;li&gt;accessing Formik methods inside useEffect&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using useFormik made the logic easier to manage. It also allowed me to directly access methods like:&lt;/p&gt;

&lt;p&gt;resetForm();&lt;br&gt;
validateForm();&lt;/p&gt;

&lt;p&gt;without relying on render props or hooks inside nested components.&lt;/p&gt;

&lt;p&gt;For multi-step forms with dynamic validation flows, this pattern felt much cleaner and more flexible than the standard  wrapper.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧪 Final Result
&lt;/h2&gt;

&lt;p&gt;Now when the user changes steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;validation updates immediately&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;isValid&lt;/code&gt; reflects current step state&lt;/li&gt;
&lt;li&gt;buttons enable/disable correctly&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🤔 Other Approaches I Tried (And Their Problems)
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Using &lt;code&gt;validateOnMount&lt;/code&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Formik&lt;/span&gt; &lt;span class="na"&gt;validateOnMount&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  ❌ Problem
&lt;/h4&gt;

&lt;p&gt;This helps only during initial mount.&lt;/p&gt;

&lt;p&gt;It does not reliably solve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dynamic schema switching&lt;/li&gt;
&lt;li&gt;multi-step validation transitions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Especially when fields change between steps.&lt;/p&gt;


&lt;h3&gt;
  
  
  2. Validating Step Fields Manually
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isStepValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentStepFields&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;every&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;field&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;formik&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;field&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  ❌ Problem
&lt;/h4&gt;

&lt;p&gt;This adds a lot of manual logic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;field tracking&lt;/li&gt;
&lt;li&gt;nested fields handling&lt;/li&gt;
&lt;li&gt;dynamic arrays&lt;/li&gt;
&lt;li&gt;conditional fields&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It works, but becomes difficult to maintain in large forms.&lt;/p&gt;


&lt;h3&gt;
  
  
  3. Using only &lt;code&gt;validateForm()&lt;/code&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;validateForm&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;currentStep&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  ❌ Problem
&lt;/h4&gt;

&lt;p&gt;This triggered validation immediately when moving to the next step, causing all fields in the new step to instantly show validation errors before the user interacted with them.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 What I Learned
&lt;/h2&gt;

&lt;p&gt;Formik works great for standard forms.&lt;/p&gt;

&lt;p&gt;But with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dynamic validation schemas&lt;/li&gt;
&lt;li&gt;multi-step flows&lt;/li&gt;
&lt;li&gt;conditional rendering&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 you sometimes need to manually synchronize validation state.&lt;/p&gt;

&lt;p&gt;The tricky part wasn’t validation itself — it was getting Formik to fully recognize the schema transition.&lt;/p&gt;


&lt;h2&gt;
  
  
  🚀 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Debugging this issue made me realize that multi-step forms often require more control over Formik’s internal lifecycle than standard forms do.&lt;/p&gt;

&lt;p&gt;Even though the validation schema was updating correctly, Formik wasn’t immediately recalculating the validation state for the newly rendered step.&lt;/p&gt;

&lt;p&gt;Using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;resetForm&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;values&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;validateForm&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;helped ensure that both the form state and validation state stayed in sync during step transitions.&lt;/p&gt;

&lt;p&gt;If you’ve run into similar issues while building multi-step forms with Formik, I’d be interested to hear what approach worked for you.&lt;/p&gt;

</description>
      <category>react</category>
      <category>formik</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
