Logo of react
React 19Functional components
Logo of vue
Vue 3.5Composition API

Slots

A slot is a placeholder inside a child component's template that allows a parent component to inject custom content, making the child component flexible and reusable by letting the parent control parts of its layout.

Example

Logo of react React 19, Functional components

ChildComponent.jsx

export default function ChildComponent({ children }) {  return <div className="wrapper">{children}</div>;}

ParentComponent.jsx

export default function ParentComponent() {  return (    <ChildComponent>      <p>Content for the child component's slot.</p>    </ChildComponent>  );}
Logo of vue Vue 3.5, Composition API

ChildComponent.vue

<template>  <div class="wrapper">    <slot />  </div></template>

ParentComponent.vue

<template>  <ChildComponent>    <p>Content for the child component's slot.</p>  </ChildComponent></template>

Fallback

Slots should have fallback (default) content.

Logo of react React 19, Functional components

IconButton.jsx

export default function IconButton({ children }) {  return (    <button className="btn">      {children || <span>πŸ‘†</span>}    </button>  );}

Usage:

export default function() {  return (    <div>      <IconButton />      <IconButton>        <span>❀️</span>      </IconButton>    </div>  );}
Logo of vue Vue 3.5, Composition API

IconButton.vue

<template>  <button class="btn">    <slot>      <span>πŸ‘†</span>    </slot>  </button></template>

Usage:

<template>  <div>    <IconButton />    <IconButton>      <span>❀️</span>    </IconButton>  </div></template>