MCPcopy Create free account
hub / github.com/adobe/react-spectrum / useSlotId

Function useSlotId

packages/react-aria/src/utils/useId.ts:135–150  ·  view source on GitHub ↗
(depArray: ReadonlyArray<any> = [])

Source from the content-addressed store, hash-verified

133 * @param depArray - When to recalculate if the id is in the DOM.
134 */
135export function useSlotId(depArray: ReadonlyArray<any> = []): string {
136 let id = useId();
137 let [resolvedId, setResolvedId] = useValueEffect(id);
138 let updateId = useCallback(() => {
139 setResolvedId(function* () {
140 yield id;
141
142 yield document.getElementById(id) ? id : undefined;
143 });
144 // oxlint-disable-next-line react/react-compiler
145 }, [id, setResolvedId]);
146
147 useLayoutEffect(updateId, [id, updateId, ...depArray]);
148
149 return resolvedId;
150}

Callers 15

useCalendarBaseFunction · 0.90
useGridListSectionFunction · 0.90
useGridListItemFunction · 0.90
useFieldFunction · 0.90
useMenuItemFunction · 0.90
useOptionFunction · 0.90
useDialogFunction · 0.90
useToastFunction · 0.90
DropZone.tsxFile · 0.90
Slots.test.jsFile · 0.90
TrayHeaderWrapperFunction · 0.90
MenuItemFunction · 0.90

Calls 2

useValueEffectFunction · 0.90
useIdFunction · 0.85

Tested by

no test coverage detected