Skip to content

ElRefSpecChild type

Home > @rimitive/view > ElRefSpecChild

Valid child types for an element

Note: Bare functions are not supported. For dynamic content, use map() or other reconciliation helpers that provide efficient updates.

The TElement parameter is kept for API consistency, but child RefSpecs/FragmentRefs use unknown since any element can be a child of any other element at runtime. Using unknown (the top type) allows proper variance - any RefSpec is assignable to RefSpec.

Signature:

export type ElRefSpecChild = string | number | boolean | null | RefSpec<unknown> | Reactive<unknown> | FragmentRef<unknown>;

References: RefSpec, Reactive, FragmentRef

import { compose } from '@rimitive/core';
import { SignalModule, ComputedModule } from '@rimitive/signals/extend';
import { createDOMAdapter } from '@rimitive/view/adapters/dom';
import { createElModule } from '@rimitive/view/el';
import type { ElRefSpecChild } from '@rimitive/view/types';
const adapter = createDOMAdapter();
const svc = compose(SignalModule, ComputedModule, createElModule(adapter));
const { el, signal, computed } = svc;
const name = signal('World');
// All valid children types
const children: ElRefSpecChild[] = [
'Hello', // string
42, // number
true, // boolean
null, // null (renders nothing)
el('span')('text'), // RefSpec
computed(() => `Hello, ${name()}!`), // Reactive
];
el('div')(...children);