【问题标题】:react-native-fast-image with React hooks crashes onLoadEnd带有 React 钩子的 react-native-fast-image 崩溃 onLoadEnd
【发布时间】:2019-06-26 09:14:31
【问题描述】:

我正在使用来自 react-native-fast-image 的 FastImage 组件和回调中的 React useState。

喜欢这个

const Avatar = (props) => {
  const [isImageUploaded, setIsImageUploaded] = useState(false);

  return (
    <View style={sizeStyle}>
      <FastImage
        source={{ uri: profileImg }}
        onLoadEnd={() => {
          setIsImageUploaded(true);
        }}
      />
    </View>
  );
};

Avatar 内部使用 FlatList 组件,当我清除其数据时,我崩溃了

没有setIsImageUploaded(true);之类的崩溃消失

<FastImage
  source={{ uri: profileImg }}
  onLoadEnd={() => {
    // setIsImageUploaded(true);
  }}
/>

我是 React 钩子的新手。关于如何正确处理此类情况的任何想法?

【问题讨论】:

    标签: reactjs react-native react-hooks


    【解决方案1】:

    我添加了检查回调是否不为空,这解决了我的问题。

    - (void)setOnFastImageLoadEnd:(RCTDirectEventBlock)onFastImageLoadEnd {
        _onFastImageLoadEnd = onFastImageLoadEnd;
        if (self.hasCompleted && _onFastImageLoadEnd != NULL) {
            _onFastImageLoadEnd(@{});
        }
    }
    

    这里是我的拉取请求https://github.com/troublediehard/react-native-fast-image/pull/1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-08
      • 2022-09-28
      • 1970-01-01
      • 2019-06-01
      • 1970-01-01
      • 2020-05-10
      • 2018-04-28
      • 2022-01-11
      相关资源
      最近更新 更多