use Status
Read the top curtain’s status from inside `Root`; the component re-renders when it changes.
Usage
Curtains animate themselves. Anything else that has to follow them, a page, a header, a loading bar, reads useStatus.
const { status, ready, key, meta } = AppScrim.useStatus();status
status is the phase of the top curtain, or idle when there's none. This site's pages rise in as soon as the curtain starts leaving:
const { status, meta } = AppScrim.useStatus();
<m.main
initial={false}
animate={
status === "covered"
? { opacity: 0, y: "4rem" }
: { opacity: 1, y: 0, transition: { duration: meta.duration, ease: meta.ease } }
}
/>ready
ready turns true once the top curtain's until has resolved, while its hold may still keep it up. A new curtain starts not ready, and with no curtain on screen ready is true, so a loading indicator only needs one check:
const { ready } = AppScrim.useStatus();
{!ready && <Spinner />}meta
meta is the one of the curtain on top, so the page above moves at the pace of whichever curtain is leaving. Once everything is idle, it stays the one of the last curtain.
Outside React
getStatus() returns the same thing where hooks can't run, like a route's beforeLoad. Before Root mounts it returns undefined.
beforeLoad: async () => {
const scrim = AppScrim.getStatus();
if (scrim?.status === "idle") await AppScrim.cover(AppCurtain);
},On the server
On the server, status is the first curtain's phase: covered if createScrim has one, idle otherwise. ready is false with a first curtain, true without. Hydration reads the same values, then the component follows the scrim.
Reference
Returns
| prop | type | default | |
|---|---|---|---|
status | "idle" | "entering" | "covered" | "leaving" | — | the phase of the top curtain, or idle |
ready | boolean | — | whether the top curtain's until has resolved; true with no curtain |
key | string | undefined | — | the key of the top curtain |
meta | Readonly<TMeta> | — | the meta of the top curtain, or of the last one |