Elements in, elements out
Pass rendered elements into slots, such as <Login />. For lists, map receives each item and returns its element.
get started
npm install react-renderableunder 1 kB minified and gzipped
The idea
Ternaries, && and .map are useful, but they can make branches and empty states easy to miss. Renderable gives those decisions names: show, switch, each and more.
Each primitive is a function component. No hooks or context to configure: use the pieces you need, or the whole set.
The types follow your data. r.each infers the item type from items, and TypeScript catches missing required props.
See it in context
projects-screen.tsxThe details
Pass rendered elements into slots, such as <Login />. For lists, map receives each item and returns its element.
Most primitives add no wrapper to the rendered tree. Use within when you want to group the selected branch.
The primitives can render on the server. r.portal handles its client-side work internally, so you can keep using it from your own files.
Under 1 kB minified and gzipped. React and React DOM are peer dependencies; there are no other runtime dependencies.
In practice
With within, the chosen branch becomes a direct, keyed child of the element you pass. AnimatePresence sees steps enter and leave, with no keys to write.
An async Server Component can fetch its data and render the list and its empty state, without turning into a client file.
Build a component on r.tag and its props follow the tag you choose: as="a" takes an href, as="div" rejects it.
your turn
let's be declarativestart with one primitive, add the rest when you need them