rvx
Version:
A signal based rendering library
27 lines • 717 B
JavaScript
import { NEXT_ID } from "./internals/next-unique-id.js";
export function uniqueId() {
const next = NEXT_ID.value;
if (typeof next === "number" && next >= Number.MAX_SAFE_INTEGER) {
NEXT_ID.value = BigInt(NEXT_ID.value) + 1n;
}
else {
NEXT_ID.value++;
}
return "rvx_" + String(next);
}
export function useUniqueId(component) {
return component(uniqueId());
}
export function UseUniqueId(props) {
return props.children(uniqueId());
}
const IDS = new WeakMap();
export function uniqueIdFor(target) {
let id = IDS.get(target);
if (id === undefined) {
id = uniqueId();
IDS.set(target, id);
}
return id;
}
//# sourceMappingURL=unique-id.js.map