選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

LazyRenderBox.js 1.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
  2. import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
  3. import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
  4. import _inherits from 'babel-runtime/helpers/inherits';
  5. import React, { Component } from 'react';
  6. import PropTypes from 'prop-types';
  7. var LazyRenderBox = function (_Component) {
  8. _inherits(LazyRenderBox, _Component);
  9. function LazyRenderBox() {
  10. _classCallCheck(this, LazyRenderBox);
  11. return _possibleConstructorReturn(this, _Component.apply(this, arguments));
  12. }
  13. LazyRenderBox.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  14. return nextProps.hiddenClassName || nextProps.visible;
  15. };
  16. LazyRenderBox.prototype.render = function render() {
  17. var _props = this.props,
  18. hiddenClassName = _props.hiddenClassName,
  19. visible = _props.visible,
  20. props = _objectWithoutProperties(_props, ['hiddenClassName', 'visible']);
  21. if (hiddenClassName || React.Children.count(props.children) > 1) {
  22. if (!visible && hiddenClassName) {
  23. props.className += ' ' + hiddenClassName;
  24. }
  25. return React.createElement('div', props);
  26. }
  27. return React.Children.only(props.children);
  28. };
  29. return LazyRenderBox;
  30. }(Component);
  31. LazyRenderBox.propTypes = {
  32. children: PropTypes.any,
  33. className: PropTypes.string,
  34. visible: PropTypes.bool,
  35. hiddenClassName: PropTypes.string
  36. };
  37. export default LazyRenderBox;