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) 679 B
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e||self).componentsSwitch={},e.react)}(this,function(e,n){function t(e){return e.children}function r(e){try{return null!=e&&("function"==typeof e?e():!!e)}catch(e){return!1}}e.Match=t,e.Switch=function(e){var i,o=e.children,c=e.fallback;try{Array.isArray(o)||(o=[o]);for(var f=[],a=0;a<o.length;++a){var l=o[a];n.isValidElement(l)&&(n.isValidElement(i=l)&&i.type===t&&"when"in i.props&&!r(l.props.when)||f.push(l))}return 0===f.length?c:f}catch(e){return c}}}); //# sourceMappingURL=components-switch.umd.js.map