control-flow-react
Version:
Control flow components for React
18 lines • 838 B
JavaScript
import React from "react";
export var Switch = function (props) {
var when = props.when, children = props.children, _a = props.fallBack, fallBack = _a === void 0 ? null : _a;
var cases = React.Children.toArray(children).filter(function (child) { return React.isValidElement(child) && child.type === Case; });
var successCase = cases.find(function (child) {
if (!React.isValidElement(child))
return false;
if (child.props.values)
return child.props.values.includes(when);
return child.props.value === when;
});
return React.createElement(React.Fragment, null, successCase ? successCase : fallBack);
};
export var Case = function (_a) {
var children = _a.children;
return (React.createElement(React.Fragment, null, children));
};
//# sourceMappingURL=switch.js.map