问题描述
这是最新的React Navigation和React Native的问题。要使其静音,请添加:
import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCtimageLoader']);
我预计它将在接下来的几周内在React Navigation中修复。
解决方法
我正在使用react-navigation实现2个屏幕。但是导航到第二页时出现以下警告:
警告:isMounted(…)在纯Javascript类中已弃用。相反,请确保在componentWillUnmount中清除订阅和未决请求,以防止内存泄漏。
版本:
- 反应:16.3.1
- 反应本机:0.55.2
- 反应导航:1.5.11
- 效用:0.10.3
Login.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,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>
)
}
}
我在这里想念什么?