Suspense data reading

Suspense 데이터 읽기

An unresolved render-time read shows the nearest fallback, then reveals content when ready.

···
html
<div class="scene"><div class="title">SUSPENSE BOUNDARY <span id="status">pending</span></div><div class="card"><div id="skeleton"><i></i><i></i><i></i></div><div id="content"><b>Result ready</b><p>Three rows resolved together</p><div class="dots">● ● ●</div></div></div><div class="progress"><span id="progress"></span></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}.title{display:flex;justify-content:space-between;font-weight:700}.title span{color:var(--accent)}.card{height:65%;display:grid;place-items:center;border:1px dashed var(--line);border-radius:9px;margin-top:10px}.card>div{width:70%;text-align:center}.card p{margin:.4em 0}.dots{color:var(--accent)}#skeleton i{display:block;height:clamp(10px,3vmin,18px);border-radius:4px;background:var(--line);margin:9px auto}#skeleton i:nth-child(2){width:75%}#skeleton i:nth-child(3){width:50%}#content{display:none}.progress{height:4px;background:var(--line);margin-top:8px}.progress span{display:block;width:0;height:100%;background:var(--accent);transition:width .3s}
js
let n=0;function tick(){const ready=n%4>=2;document.getElementById("skeleton").style.display=ready?"none":"block";document.getElementById("content").style.display=ready?"block":"none";document.getElementById("status").textContent=ready?"resolved":"pending";document.getElementById("progress").style.width=(ready?100:(n%4+1)*25)+"%";n++}tick();setInterval(tick,700)

Suspense wraps a child UI that can wait during rendering. With a Suspense-enabled data source, the boundary shows a fallback until content is ready.

The demo replaces a card skeleton with rows when data resolves. An arbitrary fetch started inside an effect does not automatically activate Suspense.

When to use

Use it to design loading boundaries for code splitting or Suspense-enabled data sources.

Open as page ↗