Unique IDs
uniqueId
Allocate an ID that is unique in the current thread.
import { uniqueId } from "rvx/id";
const id = uniqueId();
<>
<label for={id}>Name</label>
<input type="text" id={id} />
</>;
import { uniqueId, e } from "./rvx.js";
const id = uniqueId();
[
e("label").set("for", id).append("Name"),
e("input").set("type", "text").set("id", id),
]
- Returns a string in the form
"rvx_{suffix}"
. E.g."rvx_77"
- There are practically infinite ids, however when the
Number.MAX_SAFE_INTEGER
suffix is reached, the current implementation switches to usingBigInts
which will slightly degrade allocation performance.
<UseUniqueId>
A component for allocating a unique id using uniqueId
.
import { UseUniqueId } from "rvx/id";
<UseUniqueId>
{id => <>
<label for={id}>Name</label>
<input type="text" id={id} />
</>}
</UseUniqueId>
import { UseUniqueId, e } from "./rvx.js";
UseUniqueId({
children: id => [
e("label").set("for", id).append("Name"),
e("input").set("type", "text").set("id", id),
],
})