useFormStatus는 가장 가까운 부모 form의 pending 상태를 읽습니다. 제출 버튼을 별도 자식 컴포넌트로 만들면 폼 전체의 진행 여부에 맞춰 비활성화할 수 있습니다.
데모에서는 한 폼만 제출 중이 되고 옆 폼은 그대로 남습니다. 훅을 form을 렌더하는 같은 컴포넌트에서 부르면 그 form의 상태를 읽는 구조가 아닙니다.
언제 쓰나
재사용 가능한 제출 버튼이나 진행 표시를 폼 내부에 넣을 때 사용합니다.
폼 안의 자식 컴포넌트가 해당 폼의 제출 진행 상태를 읽습니다.
<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>.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}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는 가장 가까운 부모 form의 pending 상태를 읽습니다. 제출 버튼을 별도 자식 컴포넌트로 만들면 폼 전체의 진행 여부에 맞춰 비활성화할 수 있습니다.
데모에서는 한 폼만 제출 중이 되고 옆 폼은 그대로 남습니다. 훅을 form을 렌더하는 같은 컴포넌트에서 부르면 그 form의 상태를 읽는 구조가 아닙니다.
재사용 가능한 제출 버튼이나 진행 표시를 폼 내부에 넣을 때 사용합니다.