警告:isMounted(...) 在纯 Javascript 类中已弃用

新手上路,请多包涵

我正在使用反应导航实现 2 个屏幕。但是我在导航到第二页时收到了以下警告:

警告:isMounted(…) 在纯 Javascript 类中已弃用。相反,请确保清理 componentWillUnmount 中的订阅和挂起的请求,以防止内存泄漏。

版本:

  • 反应:16.3.1
  • 反应本机:0.55.2
  • 反应导航:1.5.11
  • 效用:0.10.3

登录.js

 import React, { Component } from 'react';
import { Text, View, Image, TextInput, TouchableOpacity } from 'react-native';
import styles from "./styles";

export default class Login extends Component {
    constructor(props) {
    super(props);
}

render() {
    const { navigate } = this.props.navigation;
    return (
        <View style={styles.container}>
            <View style={styles.formContainer}>
                <TouchableOpacity style={styles.button} onPress={()=> navigate('Home')} >
                    <Text style={styles.buttonText}>LOGIN</Text>
                </TouchableOpacity>
            </View>
        </View>
    )
}

首页.js

 import React, { Component } from 'react';
import { Text, View } from 'react-native';
import styles from "./styles";

export default class Home extends Component {
    constructor(props) {
        super(props);
    }
    render() {
        const { navigate } = this.props.navigation;
        return(
            <View style={styles.container}>
                <Text>Home Screen</Text>
            </View>
        )
    }
}

我在这里错过了什么?

原文由 Javascript Hupp Technologies 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 678
2 个回答

这是最新的 React Navigation 和 React Native 的问题。要使其静音,请添加:

 import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);

我希望它会在接下来的几周内在 React Navigation 中得到修复。

原文由 James 发布,翻译遵循 CC BY-SA 3.0 许可协议

实际上是 React-Native 的问题

您可以等待并检查何时有修复可用: https ://github.com/facebook/react-native/issues/18868

或者与此同时,您可以像建议的那样隐藏警告。

原文由 Erwan 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题