首页 > 解决方案 > React useNavigation 说无法对未安装的组件执行反应状态更新

问题描述

onPressing 按钮 navigation.goBack 触发警告 can't perform a react state update on unmounted component。我正在使用带有 useNavigation 挂钩的反应导航 5。找不到任何解决方法。

<View style={styles.left}>
    <TouchableRipple style={styles.back} borderless onPress={() => navigation.goBack()}>
        <View style={styles.alignContent}>
            <Icon
                iconStyle={{ left: -6 }}
                size={14}
                name="caretleft"
                type="antdesign"
                color={Colors.green[900]}
                containerStyle={{ paddingLeft: 5 }}
            />
            <Text style={{ ...styles.buttonTitle, left: -4, color: Colors.green[900] }}>Back</Text>
        </View>
    </TouchableRipple>
</View>

标签: reactjsreact-nativereact-hooksreact-navigation-v5

解决方案


推荐阅读