Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React Native如何在HOC中包装组件 介绍_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript React Native如何在HOC中包装组件 介绍

Javascript React Native如何在HOC中包装组件 介绍,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我有一个组件,它有条件地返回一个组件“Image”或包装在HOC“withCache”中的同一个组件“Image”,因此最后一个组件名为“CachedImage” 我正在做这样的事情: 条件渲染顶部组件 但是没有起作用。My Image component是一个拥有所有用于渐进式渲染图像的逻辑并扩展React.PureComponent的组件 有什么想法吗?多谢各位 class ProgressiveImage extends React.PureComponent { static pro

我有一个组件,它有条件地返回一个组件“Image”或包装在HOC“withCache”中的同一个组件“Image”,因此最后一个组件名为“CachedImage”

我正在做这样的事情:

条件渲染顶部组件 但是没有起作用。My Image component是一个拥有所有用于渐进式渲染图像的逻辑并扩展React.PureComponent的组件

有什么想法吗?多谢各位

class ProgressiveImage extends React.PureComponent {
  static propTypes = {
    theme: PropTypes.shape({
      colors: PropTypes.object.isRequired,
    }).isRequired,
    cached: PropTypes.bool,
    uri: PropTypes.string.isRequired,
    imageFadeDuration: PropTypes.number,
    thumbnailUri: PropTypes.string,
    thumbnailBlurRadius: PropTypes.number,
    thumbnailFadeDuration: PropTypes.number,
    loadingColor: PropTypes.string,
    style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
  };

  static defaultProps = {
    cached: false,
  };

  render() { // <----------------
    const {
      theme: { colors },
      cached,
      style,
    } = this.props;

    return (
      <View
        style={[
          style || styles.container,
          { backgroundColor: colors.background },
        ]}
      >
        {cached ? <CachedImage {...this.props} /> : <Image {...this.props} />} // <-------------
      </View>
    );
  }
}
const CachedImage = withCache(
  class CachedImage extends React.PureComponent {
    render() {
      return <Image {...this.props} />;
    }
  }
);
const CachedImage = withCache(Image);