Form status

폼 상태 구독

A child component inside a form reads that form’s submission status.

···
html
<div class="scene"><b>NEAREST FORM</b><div class="forms"><div class="form" id="a"><span>FORM A</span><span class="button" id="aButton">Submit</span></div><div class="form" id="b"><span>FORM B</span><span class="button" id="bButton">Submit</span></div></div><div class="label" id="note">each button reads its parent</div></div>
css
.scene{width:min(94vw,800px);height:min(86vh,320px);position:relative;overflow:hidden;display:flex;flex-direction:column;justify-content:space-between;border:1px solid var(--line);border-radius:14px;background:var(--surface);padding:clamp(9px,2.4vmin,20px);font:500 clamp(15px,4vmin,18px)/1.3 var(--font-sans,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif)}.scene b,.scene strong{font-weight:700}.label{color:var(--muted)}.code{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.pill{border:1px solid var(--line);border-radius:8px;padding:.4em .65em;background:var(--bg)}.active{border-color:var(--accent)!important;color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 10%,var(--surface))!important}.scene>b{color:var(--accent)}.forms{display:flex;gap:10px;margin:clamp(15px,6vmin,40px) 0}.form{flex:1;min-width:0;border:1px solid var(--line);border-radius:9px;padding:.6em;display:flex;flex-direction:column;gap:12px}.button{background:var(--accent);color:var(--bg);padding:.5em;border-radius:6px;text-align:center}.form.pending{border-color:var(--accent)}.form.pending .button{opacity:.5}.label{text-align:center}
js
let n=0;function tick(){const s=n%3;for(const id of ["a","b"]){const on=(s===1&&id==="a")||(s===2&&id==="b");document.getElementById(id).classList.toggle("pending",on);document.getElementById(id+"Button").textContent=on?"Pending…":"Submit"}document.getElementById("note").textContent=["each button reads its parent","A pending; B idle","B pending; A idle"][s];n++}tick();setInterval(tick,900)

useFormStatus reads the pending state of the nearest parent form. A submit button in a child component can disable itself while its form submits.

The demo makes only one form pending while the neighboring form remains idle. Calling the hook in the component that renders the form itself does not read that form’s status.

When to use

Use it for reusable submit buttons or progress indicators nested inside forms.

Open as page ↗