Skip to content

Slot Primitive

Merges its props onto its immediate child.

Install the component via your command line.

Terminal window
npx expo install @rn-primitives/slot

Slot works with any component type. Give it a single element as its child and it renders that child with the Slot’s props merged onto it. This is the building block for an asChild prop:

import { Slot } from '@rn-primitives/slot';
import { Pressable, type PressableProps } from 'react-native';
function Button({ asChild, ...props }: PressableProps & { asChild?: boolean }) {
// When `asChild` is true, the child element receives the Button's props
const Component = asChild ? Slot : Pressable;
return <Component {...props} />;
}
function Example() {
return (
<Button asChild onPress={() => console.log('pressed')}>
{/* The Link is rendered and receives the Button's `onPress` */}
<Link href="/docs" />
</Button>
);
}

When a prop exists on both the Slot and its child, they are combined instead of one silently winning:

PropBehavior
Event handlersBoth run — the child’s handler first, then the slot’s (onPress, etc.)
styleMerged into a single style array; the child’s style wins conflicts
classNameJoined together (slot’s classes first, then the child’s)
refComposed — the slot’s ref and the child’s ref both receive the node
Everything elseThe child’s value takes precedence

Slot has no props of its own — it accepts the props of whatever component its child is and forwards them.

PropTypeNote
children*React.ReactElementA single valid element. Fragments are flattened and each element inside receives the props. Plain text children are not supported.