I'm trying to make a simple loader in react native and it gives me this error
Can't perform a React state update 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 tasks in thecomponentWillUnmount
method.
my code:
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import AnimatedLoader from 'react-native-animated-loader';
export default class Loader extends React.Component {
constructor(props) {
super(props);
this.state = { visible: false };
}
componentDidMount() {
setInterval(() => {
this.setState({
visible: !this.state.visible
});
}, 6000);
}
render() {
const { visible } = this.state;
return (
<View backgroundColor={'black'} style={{ flex: 1, justifyContent:'center' }}>
<AnimatedLoader
visible={visible}
overlayColor="white"
source={require("./loader.json")}
animationStyle={styles.lottie}
speed={1}
>
<Text>Doing something...</Text>
</AnimatedLoader>
</View>
);
}
}
const styles = StyleSheet.create({
lottie: {
width: 100,
height: 100
}
});