CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react

React is a JavaScript library for building user interfaces through a declarative, component-based approach.

Pending
Overview
Eval results
Files

children.mddocs/

Children Utilities

Utilities for manipulating opaque children prop.

const Children = {
  map<T, C>(children: C | ReadonlyArray<C>, fn: (child: C, index: number) => T): T[];
  forEach<C>(children: C | ReadonlyArray<C>, fn: (child: C, index: number) => void): void;
  count(children: any): number;
  only<C>(children: C): C;
  toArray<C>(children: C | ReadonlyArray<C>): C[];
};
// Transform children
<div>
  {Children.map(children, (child, i) => 
    cloneElement(child, { index: i, isFirst: i === 0 })
  )}
</div>

// Count and validate
if (Children.count(children) > max) throw new Error('Too many children');

// Ensure single child
const child = Children.only(children);

// Flatten nested structure
const items = Children.toArray(children);

Install with Tessl CLI

npx tessl i tessl/npm-react

docs

built-in-components.md

caching.md

children.md

components.md

composition.md

context.md

development.md

elements.md

experimental.md

hooks-context.md

hooks-effects.md

hooks-imperative.md

hooks-performance.md

hooks-state.md

hooks-transitions.md

index.md

refs.md

transitions.md

tile.json