UNPKG

components-switch

Version:

A lightweight React utility component library featuring Switch and Match for conditional rendering, inspired by SolidJS. Simplifies readable and declarative conditional logic in JSX.

3 lines (2 loc) 484 B
var r=require("react");function t(r){return r.children}function n(r){try{return null!=r&&("function"==typeof r?r():!!r)}catch(r){return!1}}exports.Match=t,exports.Switch=function(e){var a,c=e.children,i=e.fallback;try{Array.isArray(c)||(c=[c]);for(var l=[],u=0;u<c.length;++u){var h=c[u];r.isValidElement(h)&&(r.isValidElement(a=h)&&a.type===t&&"when"in a.props&&!n(h.props.when)||l.push(h))}return 0===l.length?i:l}catch(r){return i}}; //# sourceMappingURL=components-switch.cjs.map