如何解决警告:isMounted…在纯Javascript类中已弃用
这是最新的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>
)
}
}
我在这里想念什么?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。