带有 React 钩子的 react-native-fast-image 在 LoadEnd 上崩溃
react-native-fast-image with React hooks crashes onLoadEnd
我在回调中使用 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 钩子的新手。关于如何正确处理此类案件的任何想法?
我添加了回调是否不为空的检查,这解决了我的问题。
- (void)setOnFastImageLoadEnd:(RCTDirectEventBlock)onFastImageLoadEnd {
_onFastImageLoadEnd = onFastImageLoadEnd;
if (self.hasCompleted && _onFastImageLoadEnd != NULL) {
_onFastImageLoadEnd(@{});
}
}
这是我的拉取请求 https://github.com/troublediehard/react-native-fast-image/pull/1
我在回调中使用 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 钩子的新手。关于如何正确处理此类案件的任何想法?
我添加了回调是否不为空的检查,这解决了我的问题。
- (void)setOnFastImageLoadEnd:(RCTDirectEventBlock)onFastImageLoadEnd {
_onFastImageLoadEnd = onFastImageLoadEnd;
if (self.hasCompleted && _onFastImageLoadEnd != NULL) {
_onFastImageLoadEnd(@{});
}
}
这是我的拉取请求 https://github.com/troublediehard/react-native-fast-image/pull/1