警告:在简单的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.