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

Function useSlot

packages/react-aria-components/src/utils.tsx:364–387  ·  view source on GitHub ↗
(
  initialState: boolean | (() => boolean) = true
)

Source from the content-addressed store, hash-verified

362}
363
364export function useSlot(
365 initialState: boolean | (() => boolean) = true
366): [RefCallback<Element>, boolean] {
367 // Initial state is typically based on the parent having an aria-label or aria-labelledby.
368 // If it does, this value should be false so that we don't update the state and cause a rerender when we go through the layoutEffect
369 let [hasSlot, setHasSlot] = useState(initialState);
370 let hasRun = useRef(false);
371
372 // A callback ref which will run when the slotted element mounts.
373 // This should happen before the useLayoutEffect below.
374 let ref = useCallback(el => {
375 hasRun.current = true;
376 setHasSlot(!!el);
377 }, []);
378
379 // If the callback hasn't been called, then reset to false.
380 useLayoutEffect(() => {
381 if (!hasRun.current) {
382 setHasSlot(false);
383 }
384 }, []);
385
386 return [ref, hasSlot];
387}
388
389/**
390 * Filters out `data-*` attributes to keep them from being passed down and duplicated.

Callers 15

ListBoxSectionInnerFunction · 0.90
NumberField.tsxFile · 0.90
Slider.tsxFile · 0.90
TextField.tsxFile · 0.90
DateField.tsxFile · 0.90
RadioGroup.tsxFile · 0.90
DatePicker.tsxFile · 0.90
Meter.tsxFile · 0.90
MenuSectionInnerFunction · 0.90
ProgressBar.tsxFile · 0.90
ComboBoxInnerFunction · 0.90
SelectInnerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected