title: React-Native: Warning: Can't perform a React state update on an unmounted component
body: <p>I am getting the following error message when I try to transition from one screen to another:</p>
  
  <p><a href="https://i.stack.imgur.com/2PeGD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2PeGD.jpg" alt="enter image description here"></a></p>
  
  <p>This is happening in a game app where multiple phones are involved in the game and have different screens depending on their role in the game and depending if that phone is hosting the game or is a guest.</p>
  
  <p>The following image shows this error message when I am trying to reach the next screen (on the left phone). The screen on the left phone is supposed to be the same as the one on the right, but without the buttons "Next Round" and "End Game". But I am getting a totally different screen with the error message:</p>
  
  <p><a href="https://i.stack.imgur.com/VJ6Kt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VJ6Kt.jpg" alt="enter image description here"></a></p>
  
  <p>Here is the code for the previous screen that is supposed to navigate the phones to this "score" screen:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import React, {Component} from 'react';
  import {AppRegistry, View, Text, ScrollView, StyleSheet} from 'react-native';
  import {CardFlip1} from '../components/CardFlip1';
  import {CardFlip2} from '../components/CardFlip2';
  import colors from '../config/colors';
  import {PrimaryButton} from '../components/PrimaryButton';
  import AsyncStorage from '@react-native-community/async-storage';
  import Orientation from 'react-native-orientation-locker';
  window.navigator.userAgent = 'react-native';
  import io from 'socket.io-client/dist/socket.io';
  
  class judge_screen extends Component {
      constructor (props) {
          super(props);
          this.state = {
              game_round: '',
              player1: '',
              player2: '',
              label1: '',
              label2: '',
              current_user: ''
          }
      }
  
      componentWillMount = () =&gt; {
          this.getActives();
      }
  
      componentDidMount() {
          Orientation.lockToLandscape();
          this.socket = io("socket address is here", {
              jsonp: false
          });
      }
  
      getActives = async () =&gt; {
          let user = await AsyncStorage.getItem('email');
          let player_1 = await AsyncStorage.getItem('Player1');
          let player_2 = await AsyncStorage.getItem('Player2');
          let round = await AsyncStorage.getItem('Round');
  
          this.setState({game_round: round});
          this.setState({player1: player_1});
          this.setState({player2: player_2});
          var label_start = "Choose ";
          var label_end = "'s fate";
          var player_1_name = this.state.player1;
          var player_2_name = this.state.player2;
          var label1_str = label_start.concat(player_1_name, label_end);
          this.setState({label1: label1_str});
          var label2_str = label_start.concat(player_2_name, label_end);
          this.setState({label2: label2_str});
      }
  
      player1Win = async () =&gt; {
          let host = await AsyncStorage.getItem('host');
          if (host == 'yes') {
              let user = await AsyncStorage.getItem('email');
              this.setState({current_user: user});
          } else {
              let user = await AsyncStorage.getItem('users_id');
              this.setState({current_user: user});
          }
          var user_fix = this.state.current_user;
          let player_name = await AsyncStorage.getItem('Player1');
          AsyncStorage.setItem('Winner', player_name);
  
          fetch('fetch address is here', {
              method: 'POST',
              headers: {
              'Accept': 'application/json',
              'Content-Type': 'application.json',
              },
              body: JSON.stringify({
                  email: user_fix,
                  Name: player_name,
                  Host: host
              })
          }).then((response) =&gt; response.json())
          .then((responseJson) =&gt; {
              if (host == 'yes') {
                  this.socket.emit('end_round', 'end');
                  this.props.navigation.navigate('end_round_host_screen');
              } else {
              // This is the navigation to the screen getting the error:
                  this.socket.emit('end_round', 'end');
                  this.props.navigation.navigate('end_round_guest_screen');
              }
          }).catch((error) =&gt; {
              console.error(error);
          });
      }
  
      player2Win = async () =&gt; {
          let host = await AsyncStorage.getItem('host');
          if (host == 'yes') {
              let user = await AsyncStorage.getItem('email');
              this.setState({current_user: user});
          } else {
              let user = await AsyncStorage.getItem('users_id');
              this.setState({current_user: user});
          }
          var user_fix = this.state.current_user;
          let player_name = await AsyncStorage.getItem('Player2');
          AsyncStorage.setItem('Winner', player_name);
  
          fetch('fetch address is here', {
              method: 'POST',
              headers: {
              'Accept': 'application/json',
              'Content-Type': 'application.json',
              },
              body: JSON.stringify({
                  email: user_fix,
                  Name: player_name,
                  Host: host
              })
          }).then((response) =&gt; response.json())
          .then((responseJson) =&gt; {
              if (host == 'yes') {
                  this.socket.emit('end_round', 'end');
                  this.props.navigation.navigate('end_round_host_screen');
              } else {
              // This is the navigation to the screen getting the error:
                  this.socket.emit('end_round', 'end');
                  this.props.navigation.navigate('end_round_guest_screen');
              }
          }).catch((error) =&gt; {
              console.error(error);
          });
      }
  
      render() {
          return (
              &lt;ScrollView&gt;
                  &lt;View style={{flexDirection: 'row'}}&gt;
                      &lt;View style={styles.container}&gt;
                          &lt;Text style={[styles.text]}&gt;
                              {this.state.player1}
                          &lt;/Text&gt;
                          &lt;CardFlip1 /&gt;
                          &lt;PrimaryButton
                              onPress={() =&gt; this.player1Win()}
                              label={this.state.label1}
                          &gt;
                          &lt;/PrimaryButton&gt;
                      &lt;/View&gt;
                      &lt;View style={styles.container}&gt;
                          &lt;Text style={[styles.text]}&gt;
                              {this.state.player2}
                          &lt;/Text&gt;
                          &lt;CardFlip2 /&gt;
                          &lt;PrimaryButton
                              onPress={() =&gt; this.player2Win()}
                              label={this.state.label2}
                          &gt;
                          &lt;/PrimaryButton&gt;
                      &lt;/View&gt;
                  &lt;/View&gt;
              &lt;/ScrollView&gt;
          );
      }
  }
  
  const styles = StyleSheet.create({
      container: {
          flex: 1,
          alignItems: 'center',
          backgroundColor: colors.backgroundColor,
          margin: 10,
          paddingBottom: 5,
          borderWidth: 1,
          borderColor: colors.borderColor,
      },
      text: {
          fontSize: 18,
          color: colors.primaryText,
          marginTop: 10,
      },
      textPadding: {
          paddingBottom: 10,
      },
      headingText: {
          fontSize: 24,
          fontWeight: '500',
          color: colors.primaryText,
          margin: 10,
      },
      textMarginHorizontal: {
          marginHorizontal: 10,
      },
  })
  
  export default judge_screen;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here is the code for the "end_round_guest_screen" that I am trying to navigate to:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import React, {Component} from 'react';
  import {View, Text, ScrollView, StyleSheet} from 'react-native';
  import colors from '../config/colors';
  import {PrimaryButton} from '../components/PrimaryButton';
  import {ScoreBoardGuest} from '../components/ScoreBoardGuest';
  import AsyncStorage from '@react-native-community/async-storage';
  import Orientation from 'react-native-orientation-locker';
  window.navigator.userAgent = 'react-native';
  import io from 'socket.io-client/dist/socket.io';
  
  class end_round_guest_screen extends Component {
      constructor (props) {
          super(props);
          this.state = {
              game_round: '',
              winner: ''
          }
      }
  
      componentWillMount = () =&gt; {
          this.getActives();
          this.getWinner();
      }
  
      componentDidMount() {
          Orientation.unlockAllOrientations();
          this.socket = io("socket address is here", {
              jsonp: false
          });
          this.socket.on('next_round', () =&gt; this.nextRound());
          this.socket.on('end_game', () =&gt; this.endGame());
      }
  
      getActives = async () =&gt; {
          let round = await AsyncStorage.getItem('Round');
          this.setState({game_round: round});
      }
  
      getWinner = async () =&gt; {
          let user = await AsyncStorage.getItem('users_id');
          //let host = await AsyncStorage.getItem('host');
  
          fetch('fetch address is here', {
              method: 'POST',
              headers: {
              'Accept': 'application/json',
              'Content-Type': 'application.json',
              },
              body: JSON.stringify({
                  email: user
              })
          }).then((response) =&gt; response.json())
          .then((responseJson) =&gt; {
              this.setState({winner: responseJson});
          }).catch((error) =&gt; {
              console.error(error);
          });
      }
  
      nextRound = () =&gt; {
          this.props.navigation.navigate('round_start_guest_screen');
      }
  
      endGame = () =&gt; {
          this.props.navigation.navigate('end_game_guest_screen');
      }
  
      render() {
          return (
              &lt;ScrollView&gt;
                  &lt;View style={{alignItems: 'center'}}&gt;
                      &lt;Text style={styles.headingText}&gt;
                          Round {this.state.game_round}
                      &lt;/Text&gt;
                      &lt;Text style={styles.text}&gt;
                          {this.state.winner} wins this round!
                      &lt;/Text&gt;
                  &lt;/View&gt;
                  &lt;View style={styles.container}&gt;
                      &lt;ScoreBoardGuest /&gt;
                  &lt;/View&gt;
              &lt;/ScrollView&gt;
          );
      }
  }
  
  const styles = StyleSheet.create({
      container: {
          flex: 1,
          alignItems: 'center',
          backgroundColor: colors.backgroundColor,
          margin: 10,
          paddingVertical: 5,
          borderWidth: 1,
          borderColor: colors.borderColor,
      },
      text: {
          fontSize: 18,
          color: colors.primaryText,
          marginTop: 10,
      },
      headingText: {
          fontSize: 24,
          fontWeight: '500',
          color: colors.primaryText,
          margin: 10,
      },
  })
  
  export default end_round_guest_screen;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The "end_round_guest_screen" shows for a second or 2 without any states loaded and then goes to that "Card Back" screen with the error message.</p>