All files MemoizedRender.js

90% Statements 9/10
85.71% Branches 6/7
100% Functions 4/4
88.89% Lines 8/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52                          4x       37x                                     10x       6x   6x 5x   1x 1x          
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
 
import memoizeState from 'memoize-state';
 
/* eslint-disable no-underscore-dangle, react/no-multi-comp */
 
class MemoizedRenderIndirect extends PureComponent {
  static propTypes = {
    value: PropTypes.any.isRequired,
  };
 
  render() {
    return this.props.value;
  }
}
 
const deproxifyShouldDive = (data, key, a) => key === '_owner' && a.$$typeof && a._store;
 
export class MemoizedRender extends PureComponent {
  static propTypes = {
    children: PropTypes.func.isRequired,
    value: PropTypes.object,
    consumer: PropTypes.any,
  };
 
  static defaultProps = {
    value: null,
    consumer: null,
  };
 
  state = {
    children: memoizeState(this.props.children, { flags: { deproxifyShouldDive } }),
  };
 
  renderProp = value => (
    <MemoizedRenderIndirect value={this.state.children(value)} fn={this.state.children} />
  );
 
  render() {
    const { value, consumer: Consumer } = this.props;
 
    if (value) {
      return this.renderProp(value);
    }
    Eif (this.props.consumer) {
      return <Consumer>{this.renderProp}</Consumer>;
    }
    return null;
  }
}