Home
Blocks

Children

11/14/2025, 1:43:28 AM modified by Marvin

A component that renders its children.

Installation

Loading...

Preview

Demo

Always render this text

Demo 2

my name is Jane and I am 21 years old and I am Female

Demo 3

my name is Jane and I am 21 years old and I am Female
import { Children } from './children';export default function Demo() {  return (    <div>      <h3>Demo</h3>      <Children name="John" age={20} getGender={() => 'Male'}>        Always render this text      </Children>      <h3>Demo 2</h3>      <Children name="Jane" age={21} getGender={() => 'Female'}>        {({ name, age, getGender }) => (          <div className="text-sm">            my name is <span className="font-bold">{name} </span>            and I am <span className="font-bold">{age} </span>            years old and I am <span className="font-bold">{getGender()}</span>          </div>        )}      </Children>      <h3>Demo 3</h3>      <Children name="Jane" age={21} getGender={() => 'Female'}>        {({ name, age, getGender }) => (          <div>            my name is {name} and I am {age} years old and I am {getGender()}          </div>        )}      </Children>    </div>  );}
export interface ChildrenProps<T> {  children?: React.ReactNode | ((props: Omit<T, 'children'>) => React.ReactNode);}export function Children<T extends Record<string, any>>(props: ChildrenProps<T> & T) {  const { children, ...restProps } = props;  if (typeof children === 'function') {    return children(restProps);  }  return children;}

Git Commit History(1 commits)

chore: 测试

Marvin
11月14日 01:43
377f483e