Activity 컴포넌트

Activity component

숨긴 화면의 상태를 보존하면서 보이는 화면에 우선순위를 줍니다.

···
html
<div class="scene"><div class="tabs"><span id="tabA">INBOX</span><span id="tabB">DRAFT</span></div><div class="panel" id="panel"><div id="inbox">3 new messages<br><small>switching tabs preserves draft</small></div><div id="draft">draft: <strong id="text">H</strong><i></i></div></div><div class="label" id="note">DRAFT hidden, state kept</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}.tabs{display:flex;gap:5px}.tabs span{flex:1;text-align:center;padding:.45em;border:1px solid var(--line);border-radius:6px}.tabs .on{background:var(--accent);color:var(--bg)}.panel{height:61%;display:grid;place-items:center;border:1px solid var(--line);border-radius:8px;margin:8px 0;text-align:center}.panel small{color:var(--muted)}#draft{display:none;font-family:ui-monospace,monospace}#draft strong{color:var(--accent)}#draft i{display:inline-block;width:2px;height:1em;background:var(--accent)}.label{text-align:center}
js
const words=["H","He","Hel","Hell","Hello"];let n=0;function tick(){const show=n%4>=2;document.getElementById("tabA").classList.toggle("on",!show);document.getElementById("tabB").classList.toggle("on",show);document.getElementById("inbox").style.display=show?"none":"block";document.getElementById("draft").style.display=show?"block":"none";if(show)document.getElementById("text").textContent=words[Math.min(Math.floor(n/2),4)];document.getElementById("note").textContent=show?"DRAFT visible, value restored":"DRAFT hidden, state kept";n++}tick();setInterval(tick,800)

React 19.2의 Activity는 visible과 hidden 모드로 UI 일부를 관리합니다. hidden 모드는 자식 상태를 유지하되 Effect를 정리하고 업데이트를 뒤로 미룹니다.

데모에서 메모 탭을 숨겼다가 다시 열어도 입력한 글이 남습니다. 숨긴 화면에서 계속 동작해야 하는 외부 연결은 Effect 정리의 영향을 고려해야 합니다.

언제 쓰나

탭·뒤로 가기 화면의 입력 상태를 보존하고 다음 화면을 미리 준비할 때 사용합니다.

페이지로 열기 ↗