I
I
Ilya2019-04-08 18:04:29
React Native
Ilya, 2019-04-08 18:04:29

How to solve the problem with forceUpdate?

Hi there is a componentDidMount which fires two functions at a specific interval:

componentDidMount() {
       
            setInterval(() => {

                this.CheckingSetting()
                this.OtherCheckingSetting()
    
            }, 10000);
      

    }

Everything basically works, but the error keeps appearing:
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 tasks in the componentWillUnmount method.%s,
Please help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-04-08
@ynizhenie

class Example extends React.Component {
  interval;

  componentDidMount() {
    this.interval = setInterval(() => { /* ... */ }, 3000);
  }

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question