android平台运行react native 退出重新进。。报错Warning: setState(...)



  • Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the RNBlueTooth component.
    报错。。跪求解答

    /**

    import React, { Component } from 'react';
    import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    BackAndroid,
    Alert
    } from 'react-native';

    class RNBlueTooth extends Component {
    constructor(props) {
    super(props);
    this.state = { showText: true };

        // 每1000毫秒对showText状态做一次取反操作
        setInterval(() => {
            this.setState({ showText: !this.state.showText });
        }, 1000);
        
        
    }
    
    render() {
        let display = this.state.showText ? "12346" : ' ';
        return (
          <Text>{display}</Text>
        );
    }
    

    }

    const styles = StyleSheet.create({
    container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
    },
    welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
    },
    instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
    },
    });

    AppRegistry.registerComponent('RNBlueTooth', () => RNBlueTooth);


  • administrators

    是官方的一个bug 请静待更新



  • 主要是打开了监听事件一定要在退出的情况下释放掉定时器就没问题了


登录后回复