React Native Navigation Mana Leak(无法在未安装的组件上调用setState。这是空操作,但它指示..)

时间:2018-06-21 08:52:20

标签: reactjs react-native

我猜想我需要关闭LoginScreen中的一些异步任务,因为当我按下侧面抽屉上的按钮时,错误会弹出。错误消息指出泄漏为LoginScreen(由Connect(LoginScreen)创建)。是否可以通过componentwillUnmount方法取消我的异步操作?还是导航对此负责?

import React, { Component } from 'react';
import { StyleSheet, View, ScrollView,ActivityIndicator } from 'react- 
native';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import Logo from './logo';
import LoginPanel from './loginPanel';
import {autoSignIn} from '../../Store/actions';
import Tabs from '../Tabs';


class LoginScreen extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: true,
      logoAnimation: false,
    }
    showLogin = () => {
      this.setState({
        logoAnimation: true
      })
    }

  componentDidMount(){
    this.props.autoSignIn().then(()=>{
          Tabs();
    })           
   }

  render() {
    if (this.state.loading) {
      return (
        <View style={styles.loading}>
          <ActivityIndicator />
         </View>
      )
    } else {
      return (
        <ScrollView>
          <View style={styles.container}>
            <Logo
              showLogin={this.showLogin}
            />
            <LoginPanel
              navigator={this.props.navigator}
              show={this.state.logoAnimation}              
            />
          </View>
        </ScrollView>
      );
    }
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
  },
  loading: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  }
});

function mapStateToProps (state) {
  return {
    User: state.User
  }
}

function mapDispatchToProps(dispatch){
  return bindActionCreators({ autoSignIn },dispatch)
}

export default connect(mapStateToProps,mapDispatchToProps)(LoginScreen);

0 个答案:

没有答案