Slot

Merges its props onto its immediate child.

Features

  • Can be used to support your own `asChild` prop.

Install the component from your command line.

npm install @radix-ui/react-slot

Import the component.

import { Slot } from '@radix-ui/react-slot';
export default () => (
<Slot>
<div>Hello</div>
</Slot>
);

Use to create your own asChild API.

// your-button.jsx
import React from 'react';
import { Slot } from '@radix-ui/react-slot';
function Button({ asChild, ...props }) {
const Comp = asChild ? Slot : 'button';
return <Comp {...props} />;
}
import { Button } from './your-button';
export default () => (
<Button asChild>
<a href="/contact">Contact</a>
</Button>
);