
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
create-slot
Advanced tools
Render React content elsewhere in your component tree — without portals, props drilling, or state juggling. `create-slot` gives you ergonomic, type-safe slots that can be filled by features anywhere in your app and rendered inside one or more designated h
Render React content elsewhere in your component tree — without portals, props drilling, or state juggling. create-slot gives you ergonomic, type-safe slots that can be filled by features anywhere in your app and rendered inside one or more designated hosts.
create-slot?useProps().order.npm install create-slot
# or
pnpm add create-slot
# or
yarn add create-slot
import * as React from "react"
import { createSlot } from "create-slot"
// 1) Define your slots
const Slots = {
Menu: createSlot<{ n: number; inc: () => void }>(),
}
// 2) Place a Host where content should render
function Menu() {
const [n, inc] = React.useReducer((x) => x + 1, 0)
return (
<aside>
<h1>
Menu <button onClick={inc}>{n}</button>
</h1>
<ul>
<li>Home</li>
<li>Products</li>
<Slots.Menu.Host n={n} inc={inc}>
<li>Placeholder</li>
</Slots.Menu.Host>
</ul>
</aside>
)
}
// 3) Fill the slot from anywhere
function FeatureA() {
const [n, inc] = React.useReducer((x) => x + 1, 0)
return (
<Slots.Menu order={0}>
<li>
Feature A <button onClick={inc}>Inner counter: {n}</button>
</li>
</Slots.Menu>
)
}
function FeatureB() {
return (
<Slots.Menu order={1}>
<li>
Feature B <HostPropsExample />
</li>
</Slots.Menu>
)
}
function HostPropsExample() {
const { n, inc } = Slots.Menu.useProps()
return <button onClick={inc}>Host counter: {n}</button>
}
createSlot<T>() returns a Slot component with two extras: Host and useProps().<Slot/> register a “fill” (a React element). Mounting/unmounting updates every mounted Host.Host renders either its children (as a default) or the active fills, in order.useProps() gives fills access to the nearest Host props — so fills can adapt per host.This enables patterns like a shared menu that features can contribute to, or multiple lists where each item adapts to its host’s props.
function createSlot<T>(): Slot<T>
type Slot<Props> = React.FC<{
children: React.ReactElement
order?: number
}> & {
Host: React.FC<React.PropsWithChildren<Props>>
useProps(): Props
}
<Slot order?>: Registers a fill to be rendered inside every mounted Slot.Host. order controls position.<Slot.Host {...props}>default</Slot.Host>: Declares where fills render and provides typed props to fills via useProps().Slot.useProps(): Access the current host’s props from within a fill.Behavioral notes:
useProps() reflects the props of the host doing the rendering.Multiple hosts (grids, lists, toolbars)
const Slots = { Item: createSlot<{ n: number }>() }
function Grid() {
return (
<ul>
{[1, 2, 3].map((n) => (
<Slots.Item.Host key={n} n={n}>
<li>Default {n}</li>
</Slots.Item.Host>
))}
</ul>
)
}
function CustomItem() {
const { n } = Slots.Item.useProps()
if (n === 2) return null // selectively hide on a specific host
return <li>Custom {n}</li>
}
function Feature() {
return (
<Slots.Item>
<CustomItem />
</Slots.Item>
)
}
Delayed/default content
const Slots = { Delayed: createSlot() }
function PlaceholderArea() {
return (
<Slots.Delayed.Host>
<li>Loading default…</li>
</Slots.Delayed.Host>
)
}
function FillLater() {
return (
<Slots.Delayed>
<li>Loaded content</li>
</Slots.Delayed>
)
}
Typed host props
const Slots = { Menu: createSlot<{ n: number; inc: () => void }>() }
function HostPropsExample() {
const { n, inc } = Slots.Menu.useProps()
return <button onClick={inc}>Host counter: {n}</button>
}
create-slot composes UI logically and keeps context local to each host.First-class types. Pass your host prop type to createSlot<T>() and use Slot.useProps() for strict inference.
order.order to each fill.useLayoutEffect internally, which runs on the client. Rendering on the server is fine; effects run after hydration.See src/app.tsx for a small demo showcasing:
Menu with host props and interactive fillsMenuItem)Delayed)MIT
FAQs
Render React content elsewhere in your component tree — without portals, props drilling, or state juggling. `create-slot` gives you ergonomic, type-safe slots that can be filled by features anywhere in your app and rendered inside one or more designated h
The npm package create-slot receives a total of 113 weekly downloads. As such, create-slot popularity was classified as not popular.
We found that create-slot demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.