Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't call setState (or forceUpdate) on an unmounted component #2

Open
Kodax9 opened this issue Apr 6, 2018 · 2 comments
Open

Can't call setState (or forceUpdate) on an unmounted component #2

Kodax9 opened this issue Apr 6, 2018 · 2 comments

Comments

@Kodax9
Copy link

Kodax9 commented Apr 6, 2018

Hello, anyone encountered same issue as mine ?
on running after splash i got warning : Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous task in the componentWillUnmount method.

@Biplovkumar
Copy link

Same here.plz provide solution

@Biplovkumar
Copy link

@Kodax9

//this code is splash screen.jf file

import React, { Component } from 'react'
import { StyleSheet, Text,Image, View } from 'react-native'
export default class Splash extends Component {
constructor(props) {
super(props)
this.state = {timer: 0};
}

tick() {
    this.setState(prevState => ({
        timer: prevState.timer + 1
    }));
}

componentDidMount() {
    this.interval = setInterval(() => this.tick(), 1000);
}

componentWillUnmount() {
    clearInterval(this.interval);
}


render() {

    return (

        <View style={styles.container}>
            <View style={styles.logoContainer}>
                <Image style={styles.logo}
                       source={require('../images/logo.png')}>
                </Image>
            <Text style={styles.title}>{`Welcome to metso App: ${this.state.timer}`}</Text>
            {/* <Text style={styles.title}>{`Hello Splash`}</Text> */}
        </View>
        </View>
    )
}

}
const styles = StyleSheet.create({
container: {
backgroundColor: 'rgb(32, 53, 70)',
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
logoContainer: {
alignItems: 'center',
justifyContent: 'center',
flex: 1
},
logo: {
width: 320,
height: 96,
},
title: {

    fontWeight: 'bold',
    color: '#f7c744',
    fontSize: 22,
    textAlign: 'center',
    marginTop: 5,
    opacity: 0.9
},

}
)

thanks @sunlight3d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants