Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: isMounted(...) is deprecated in plain Javascript Classes

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

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

Versions:

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

What am I missing here?

like image 562
Javascript Hupp Technologies Avatar asked Apr 12 '18 06:04

Javascript Hupp Technologies


3 Answers

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']);

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

like image 77
James Avatar answered Nov 07 '22 01:11

James


Is is actually a React-Native issue

You can wait and check when a fix is available here: https://github.com/facebook/react-native/issues/18868

Or in the meantime you can hide the warning like suggested.

like image 7
Erwan Avatar answered Nov 07 '22 00:11

Erwan


Use this statement in index.js:

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);
like image 1
Diksha Nagpal Avatar answered Nov 07 '22 00:11

Diksha Nagpal