[]previous and next page

withHydration

Runs fn with the hydration flag set, so the hooks created inside see isHydrating return true, and restores the previous flag in finally.

Runs fn with the hydration flag set, so the hooks created inside see isHydrating return true, and restores the previous flag in finally. Renderers wrap their hydration pass in it (the hydrate() of @shadow-js/web does); application code does not need it.

Import#

ts
import { withHydration } from "@shadow-js/core/extend";

Signature#

ts
function withHydration<T>(fn: () => T): T

Parameters#

Name Description
fn The hydration pass. A throw is rethrown after the flag is restored.

Returns#

What fn returns.

Examples#

ts
import { isHydrating, withHydration } from "@shadow-js/core/extend";

const during = withHydration(() => isHydrating()); // true
const after = isHydrating(); // false again