React Medium technical 0 views 1 min read

What are useFormState and useFormStatus hooks?

Peer-reviewed by HireXTech Technical Panel Updated for 2025/2026 hiring Editorial standards
Practise this track
Interviewer Expectations for this Question
01
Core Competency

Assesses fundamental understanding of React conventions, runtime behavior, and memory/performance considerations.

02
Evaluation Criteria

Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.

Comprehensive Model Answer Verified Solution

These hooks simplify form handling with Server Actions in React 19.

#### useFormState
Manages form state and handles server responses:

     'use client'
     import { useFormState } from 'react-dom';
     import { loginAction } from './actions';

     export default function LoginForm() {
       const [state, formAction] = useFormState(loginAction, {
         errors: {},
         message: ''
       });

       return (
         <form action={formAction}>
           <input name="email" type="email" />
           {state.errors.email && <p>{state.errors.email}</p>}
           
           <input name="password" type="password" />
           {state.errors.password && <p>{state.errors.password}</p>}
           
           <button type="submit">Login</button>
           {state.message && <p>{state.message}</p>}
         </form>
       );
     }
     

#### useFormStatus
Get the pending state of parent form:

     'use client'
     import { useFormStatus } from 'react-dom';

     function SubmitButton() {
       const { pending, data, method, action } = useFormStatus();
       
       return (
         <button type="submit" disabled={pending}>
           {pending ? 'Submitting...' : 'Submit'}
         </button>
       );
     }

     // Must be used in a child component of <form>
     export default function MyForm() {
       return (
         <form action={serverAction}>
           <input name="email" />
           <SubmitButton />
         </form>
       );
     }
     

#### Combining Both

     'use client'
     import { useFormState, useFormStatus } from 'react-dom';

     function SubmitButton() {
       const { pending } = useFormStatus();
       return (
         <button disabled={pending}>
           {pending ? '⏳ Saving...' : '💾 Save'}
         </button>
       );
     }

     export default function EditProfile() {
       const [state, formAction] = useFormState(updateProfile, null);

       return (
         <form action={formAction}>
           <input name="name" defaultValue={user.name} />
           <input name="bio" defaultValue={user.bio} />
           <SubmitButton />
           {state?.success && <p>✅ Profile updated!</p>}
           {state?.error && <p>❌ {state.error}</p>}
         </form>
       );
     }
     

#### Key Points

  • useFormState: For managing server responses and errors
  • useFormStatus: For UI feedback during submission
  • useFormStatus must be used in a child component of the form
  • Works seamlessly with Server Actions

Candidate Response Strategy & Interview Tips

  1. Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
  2. Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
  3. Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
  4. Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.
Related Topics & Skills
Spotted an error or have an alternative solution?