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

Javascript Hupp Technologies picture Javascript Hupp Technologies · Apr 12, 2018 · Viewed 14.9k times · Source

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?

Answer

James picture James · Apr 12, 2018

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.