Options
All
  • Public
  • Public/Protected
  • All
Menu

@twocatmoon/react-slot

Index

Type aliases

Functions

Type aliases

SlotProps: React.PropsWithChildren<any> & { name: string }
Slots: {}

Type declaration

  • [key: string]: any

Functions

  • Slot(props: any): Element
  • Provides children to a component's slots.

    component
    example
    export default function () {
    return (
    <MyComponent>
    <Slot name="foo"><span>foo</span></Slot>
    <Slot name="bar"><span>bar</span></Slot>
    <span>baz</span>
    </MyComponent>
    )
    })

    Parameters

    • props: any

    Returns Element

  • findSlots(children: any): Slots
  • Finds root-level instances of slot components and maps their children to an object.

    example
    export default function MyComponent ({ children }) {
    const slots = findSlots(children)

    return (
    <div>
    <div>{slots.foo}</div>
    <div>{slots.bar}</div>
    <div>{slots.defaultSlot}</div>
    </div>
    )
    })

    Parameters

    • children: any

      Component children

    Returns Slots

    Object of children mapped to slot names

Generated using TypeDoc