UNPKG

@misa198/react-slots

Version:

A simple react component that uses slots to render children

3 lines (2 loc) 435 B
"use strict";var e=require("react");function r(e){return null}exports.Slot=function({element:r}){return r?e.cloneElement(r):null},exports.SlotWrapper=r,exports.useSlots=t=>e.useMemo((()=>{const e={},n=t=>{if(t&&"object"==typeof t&&"props"in t&&"type"in t){const{props:{children:n,name:o},type:{name:s}}=t;s===r.name&&n&&o&&(e[o]={element:n})}};return t&&(Array.isArray(t)?t.forEach(n):n(t)),e}),[t]); //# sourceMappingURL=index.js.map