我在回调中使用来自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>
);
};在FlatList中使用的Avatar组件,当我清除它的数据时,我遇到了崩溃

在没有setIsImageUploaded(true);的情况下崩溃消失
<FastImage
source={{ uri: profileImg }}
onLoadEnd={() => {
// setIsImageUploaded(true);
}}
/>我是第一次接触React hooks。有没有关于如何正确处理这种情况的想法?
发布于 2019-06-27 20:06:00
我添加了检查if callback isn null,这解决了我的问题。
- (void)setOnFastImageLoadEnd:(RCTDirectEventBlock)onFastImageLoadEnd {
_onFastImageLoadEnd = onFastImageLoadEnd;
if (self.hasCompleted && _onFastImageLoadEnd != NULL) {
_onFastImageLoadEnd(@{});
}
}这里是我的拉取请求https://github.com/troublediehard/react-native-fast-image/pull/1
https://stackoverflow.com/questions/56769224
复制相似问题