[]previous and next page

ResolvedChildren

The value returned by children: calling it yields one leaf, an array of several leaves, or undefined for none; toArray() always returns an array.

The value returned by children: calling it yields one leaf, an array of several leaves, or undefined for none; toArray() always returns an array. The methods mirror React's Children helpers.

Import#

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

Signature#

ts
interface ResolvedChildren {
  /**
   * The current children: one leaf, an array of several leaves, or `undefined` when there is none.
   * The read is tracked like a memo read.
   */
  (): unknown;
  /** A fresh array of the leaves, without `null`, `undefined` or booleans. */
  toArray(): unknown[];
  /** Number of leaves, zero or more (the React `Children.count`). */
  count(): number;
  /** Maps each leaf with its index; the callback runs untracked (React `Children.map`). */
  map<U>(fn: (leaf: unknown, index: number) => U): U[];
  /** Visits each leaf with its index; the callback runs untracked (React `Children.forEach`). */
  forEach(fn: (leaf: unknown, index: number) => void): void;
  /**
   * The single leaf (React `Children.only`). Throws a TypeError (production message
   * `SHADOW_CHILDREN_ONLY`) when there is not exactly one leaf.
   */
  only(): unknown;
}

Members#

Name Type Description
toArray toArray(): unknown[] A fresh array of the leaves, without null, undefined or booleans.
count count(): number Number of leaves, zero or more (the React Children.count).
map map<U>(fn: (leaf: unknown, index: number) => U): U[] Maps each leaf with its index; the callback runs untracked (React Children.map).
forEach forEach(fn: (leaf: unknown, index: number) => void): void Visits each leaf with its index; the callback runs untracked (React Children.forEach).
only only(): unknown The single leaf (React Children.only). Throws a TypeError (production message SHADOW_CHILDREN_ONLY) when there is not exactly one leaf.