UNPKG

react-case-when

Version:

Small utility module for conditional rendering in React

36 lines (25 loc) 1.02 kB
'use strict'; exports.__esModule = true; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _match = require('./match'); var _match2 = _interopRequireDefault(_match); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } function Case(_ref) { var when = _ref.when, children = _ref.children, _ref$as = _ref.as, Wrap = _ref$as === undefined ? _react.Fragment : _ref$as, props = _objectWithoutProperties(_ref, ['when', 'children', 'as']); if ((0, _match2.default)(when)) { return _react2.default.createElement( Wrap, props, children instanceof Function ? children() : children ); } return null; } exports.default = Case; module.exports = exports['default'];