UNPKG

rvx

Version:

A signal based rendering library

51 lines (50 loc) 1.34 kB
import type { Component, Content } from "../core/types.js"; /** * Allocate an ID that is unique in the current thread. * * @returns The unique id in the form `rvx_123`. */ export declare function uniqueId(): string; /** * A component that provides a unique id in the form `rvx_123` to it's children. * * See {@link UseUniqueId `<UseUniqueId>`} when using JSX. * * @example * ```tsx * import { useUniqueId, e } from "rvx"; * * useUniqueId(id => [ * e("label").set("for", id).append("Text"), * e("input").set("type", "text").set("id", id), * ]) * ``` */ export declare function useUniqueId<T = Content>(component: Component<string, T>): T; /** * A component that provides a unique id in the form `rvx_123` to it's children. * * See {@link useUniqueId} when not using JSX. * * @example * ```tsx * import { UseUniqueId } from "rvx"; * * <UseUniqueId> * {id => <> * <label for={id}>Text</label> * <input type="text" id={id} /> * </>} * </UseUniqueId> * ``` */ export declare function UseUniqueId<T = Content>(props: { children: Component<string, T>; }): T; /** * Get a {@link uniqueId unique id} for the specified object. * * @param target The target object. * @returns The id. This is always the same id for the same object. */ export declare function uniqueIdFor(target: object): string;