警告:在简单的Javascript类中不推荐使用isMounted(...) [英] Warning: isMounted(...) is deprecated in plain Javascript Classes

查看:313
本文介绍了警告:在简单的Javascript类中不推荐使用isMounted(...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am implementing 2 screens using react-navigation. But I got the warning below while navigating to the second page:


警告:isMounted(...)在普通Javascript类中已弃用。相反,请确保清除componentWillUnmount中的订阅和待处理请求以防止内存泄漏。

Warning: isMounted(...) is deprecated in plain Javascript Classes. Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks.

版本:


  • react:16.3.1

  • react-native:0.55.2

  • react -navigation:1.5.11

  • util:0.10.3

  • react: 16.3.1
  • react-native: 0.55.2
  • react-navigation: 1.5.11
  • util: 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>
    )
}

Home.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>
        )
    }
}

我在这里缺少什么?

推荐答案

这是最新的React Navigation和React Native的问题。要沉默它,请添加:

This is a problem with latest React Navigation and React Native. To silence it add:

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

我预计它将在未来几周内在React Navigation中修复。

I expect it will be fixed in React Navigation within next few weeks.

这篇关于警告:在简单的Javascript类中不推荐使用isMounted(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆