gpt4 book ai didi

javascript - 警告 : isMounted(. ..) 在普通 Javascript 类中已被弃用

转载 作者:行者123 更新时间:2023-12-03 13:00:14 24 4
gpt4 key购买 nike

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

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 原生:0.55.2
  • react 导航: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, { 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 的问题。要使其静音,请添加:

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

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

关于javascript - 警告 : isMounted(. ..) 在普通 Javascript 类中已被弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49789150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com