MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useSlot

Function useSlot

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

Source from the content-addressed store, hash-verified

347}
348
349export function useSlot(
350 initialState: boolean | (() => boolean) = true
351): [RefCallback<Element>, boolean] {
352 // Initial state is typically based on the parent having an aria-label or aria-labelledby.
353 // 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
354 let [hasSlot, setHasSlot] = useState(initialState);
355 let hasRun = useRef(false);
356
357 // A callback ref which will run when the slotted element mounts.
358 // This should happen before the useLayoutEffect below.
359 let ref = useCallback(el => {
360 hasRun.current = true;
361 setHasSlot(!!el);
362 }, []);
363
364 // If the callback hasn't been called, then reset to false.
365 useLayoutEffect(() => {
366 if (!hasRun.current) {
367 setHasSlot(false);
368 }
369 }, []);
370
371 return [ref, hasSlot];
372}
373
374/**
375 * 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