[]previous and next page

Context (@shadow-js/core)

A context made by createContext: a value that a subtree receives from the nearest provider above it.

A context made by createContext: a value that a subtree receives from the nearest provider above it. The context is itself the provider component; Provider is the same function.

Import#

ts
import type { Context } from "@shadow-js/core";

Signature#

ts
interface Context<T> {
  /**
   * Renders `children` with `value` provided. The value is read once, when the provider is created;
   * provide an accessor or a store for a value that changes. Returns an accessor of the children.
   */
  (props: { value: T; children?: unknown }): unknown;
  /** The unique key the provided value is stored under, described by the context's `name`. */
  readonly id: symbol;
  /** The value {@link useContext} returns without a provider. `undefined` means none: it throws. */
  readonly defaultValue: T | undefined;
  /** The same component, for code written as `<Ctx.Provider value={...}>`. */
  readonly Provider: (props: { value: T; children?: unknown }) => unknown;
}

Members#

Name Type Description
T T
id readonly id: symbol The unique key the provided value is stored under, described by the context's name.
defaultValue readonly defaultValue: T | undefined The value useContext returns without a provider. undefined means none: it throws.
Provider readonly Provider: (props: { value: T; children?: unknown }) => unknown The same component, for code written as <Ctx.Provider value={...}>.