MCPcopy
hub / github.com/preactjs/preact / useId

Function useId

hooks/src/index.js:420–436  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

418
419/** @type {() => string} */
420export function useId() {
421 /** @type {import('./internal').IdHookState} */
422 const state = getHookState(currentIndex++, 11);
423 if (!state._value) {
424 // Grab either the root node or the nearest async boundary node.
425 /** @type {import('./internal').VNode} */
426 let root = currentComponent._vnode;
427 while (root !== null && !root._mask && root._parent !== null) {
428 root = root._parent;
429 }
430
431 let mask = root._mask || (root._mask = [0, 0]);
432 state._value = 'P' + mask[0] + '-' + mask[1]++;
433 }
434
435 return state._value;
436}
437
438/**
439 * After paint effects consumer.

Callers 12

CompFunction · 0.90
ChildFunction · 0.90
SomeMessageFunction · 0.90
StatefulFunction · 0.90
ComponentFunction · 0.90
FooFunction · 0.90
AppFunction · 0.90
BarFunction · 0.90
IdFunction · 0.90
IdFunction · 0.85
FieldFunction · 0.85
WrapperFunction · 0.85

Calls 1

getHookStateFunction · 0.85

Tested by 12

CompFunction · 0.72
ChildFunction · 0.72
SomeMessageFunction · 0.72
StatefulFunction · 0.72
ComponentFunction · 0.72
FooFunction · 0.72
AppFunction · 0.72
BarFunction · 0.72
IdFunction · 0.72
IdFunction · 0.68
FieldFunction · 0.68
WrapperFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…