react-case-when
Version:
Small utility module for conditional rendering in React
20 lines (14 loc) • 450 B
JavaScript
import React from 'react';
import match from './match';
function Switch(_ref) {
var children = _ref.children;
var matched = null;
React.Children.forEach(children, function (child) {
var condition = !matched && React.isValidElement(child) && match(child.props.when);
if (condition) {
matched = child;
}
});
return matched ? React.cloneElement(matched, null, matched.props.children) : matched;
}
export default Switch;