useFormStatus and useFormState are new React 19 hooks for working with forms and Server Actions.
Simple analogy: Imagine you are sending a package by mail.
useFormStatus — form status:
1import { useFormStatus } from 'react-dom';23function SubmitButton() {4 const { pending, data, method, action } = useFormStatus();56 return (7 <button type="submit" disabled={pending}>8 {pending ? 'Sending...' : 'Submit'}9 </button>10 );11}1213function MyForm() {14 return (15 <form action={createOrder}>16 <input name="email" />17 <SubmitButton /> {/* Knows the status of the parent form! */}18 </form>19 );20}
useFormState — form result:
1import { useFormState } from 'react-dom';23function MyForm() {4 const [state, formAction] = useFormState(createOrder, { status: 'idle' });56 return (7 <form action={formAction}>8 {state.status === 'success' && <p>Order created!</p>}9 {state.status === 'error' && <p>Error: {state.message}</p>}10 <input name="email" />11 <button type="submit">Submit</button>12 </form>13 );14}
These hooks replace useReducer for forms and make code simpler and clearer.