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) • 475 B
JavaScript
import{isValidElement as r}from"react";function n(r){return r.children}function t(r){try{return null!=r&&("function"==typeof r?r():!!r)}catch(r){return!1}}function e(e){var c,o=e.children,u=e.fallback;try{Array.isArray(o)||(o=[o]);for(var a=[],h=0;h<o.length;++h){var i=o[h];r(i)&&(r(c=i)&&c.type===n&&"when"in c.props&&!t(i.props.when)||a.push(i))}return 0===a.length?u:a}catch(r){return u}}export{n as Match,e as Switch};
//# sourceMappingURL=components-switch.esm.mjs.map