UNPKG

@solid-primitives/range

Version:

Control Flow Primitives for displaying given number or a number range of elements.

40 lines (39 loc) 1.4 kB
import { type Accessor, type JSX } from "solid-js"; /** * Reactively maps a number range of specified length with a callback function - underlying helper for the `<Repeat>` control flow. * @param times number of the elements to map * @param mapFn reactive function used to create mapped output item array * @param options a fallback for when the input list is empty or missing * @returns mapped input array signal * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/range#repeat * @example * ```tsx * const [length, setLength] = createSignal(10) * const mapped = repeat(length, index => { * const [value, setValue] = createSignal(index); * createEffect(() => {...}) * return value * }) * ``` */ export declare function repeat<T>(times: Accessor<number>, mapFn: (i: number) => T, options?: { fallback?: Accessor<T>; }): Accessor<T[]>; /** * Creates a range of elements `of` specified size. * @param times number of elements * @param fallback element returned when `of` equals 0 * @param children render function * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/range#Repeat-1 * @example * ```tsx * <Repeat times={10}> * {n => <div>{n}</div>} * </Repeat> * ``` */ export declare function Repeat<T>(props: { times: number; fallback?: T; children: ((index: number) => T) | T; }): JSX.Element;