UNPKG

react-case-when

Version:

Small utility module for conditional rendering in React

24 lines (19 loc) 715 B
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } import React, { Fragment } from 'react'; import match from './match'; function Case(_ref) { var when = _ref.when, children = _ref.children, _ref$as = _ref.as, Wrap = _ref$as === undefined ? Fragment : _ref$as, props = _objectWithoutProperties(_ref, ['when', 'children', 'as']); if (match(when)) { return React.createElement( Wrap, props, children instanceof Function ? children() : children ); } return null; } export default Case;