React Interlude
Keep a loading screen over your page until it’s ready. You control the animation.
The problem
When a page appears before it has finished loading, you can see it fall into place: text switches fonts, images arrive one by one, and the layout shifts as you read.
A loading screen can hide the shifting, but someone still has to coordinate it: wait for the page, respect the animation, and avoid a flash when everything loads quickly.
React Interlude coordinates that handoff. You build the curtain—the loading screen people see—and tell React Interlude what the page needs before the curtain can leave. The curtain on this page is React Interlude at work.
Your curtain, your animation
The curtain is an ordinary React component. Give it the look you want and animate it with CSS, Motion, GSAP, or another tool. React Interlude decides when it appears and leaves; your component decides how it moves.
It receives its current phase as interlude.phase. When an entrance or exit animation finishes, call interlude.done() to hand control back:
const Curtain = ({ interlude }) => (
<div className="curtain" data-phase={interlude.phase} onTransitionEnd={interlude.done} />
);Phases
When the curtain covers a page, it moves through entering, covered, and leaving, in that order. Once it is gone, the status is idle and the curtain unmounts unless you ask it to stay.
Call done() when the entrance or exit animation finishes. The curtain stays covered until both until and hold have finished, then starts leaving.
Covering the first render
By default, the curtain starts covered, so the page is hidden from its first render. Set until to the work the page needs, such as loading its fonts, and hold to the shortest time the curtain should stay visible. That minimum keeps a fast, cached page from flashing the curtain on and off:
<Interlude curtain={Curtain} hold={650} until={() => document.fonts.ready}>
<App />
</Interlude>