-1

I have probleme with React-Native (I use Expo).
I pass a function in componentDidMount() which makes a call to action (redux) to retrieve data from the API.
When I close the application and I open it's again, I have this error:

Warning: 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 %s.%s, the componentWillUnmount method

I tried several methods like this :
https://github.com/material-components/material-components-web-react/issues/434
React-Native: Warning: Can't perform a React state update on an unmounted component
And other similair methods that I found on Stack overflow, but nothing works and the error is still present.

Anybody had this problem before ?
Could you please help me to resolve this problem ?

alexandre_plt
  • 51
  • 1
  • 8

1 Answers1

0

I am not sure the react-native would be the same issue as I had with reactjs, but when on my react app it was complaining the memory leak error I just had to add AbortController().

You can try something like this

abortController = new AbortController();

componentDidMount() {
    fetch('url', {
      signal: this.abortController.signal,
    }).then((res) => {
      // do something
    }).catch((err) => {
        if (err.name === 'AbortError') {
          // throw error;
        }
    })

    componentWillUnmount() {
      this.abortController.abort();
    }
}

Hope this helps.