Skip to content

Conversation

jhicken
Copy link

@jhicken jhicken commented Apr 13, 2021

I have a case where I am intentionally unmounting and remounting before the debounce gets run in the call stack. And I get errors from react telling me I have a memory leak. This makes that error go away.

I have a case where I am intentionally unmounting and remounting before the debounce gets run in the call stack. And I get errors from react telling me I have a memory leak. This makes that error go away.
const truncatedString = this.getTruncateString(this.props.text)
this.setState({truncatedString, truncating: false})
})
if (this._isMounted) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other approach here, might be to change debounce to a this.timeoutId = setTimeout(...). When the component unmounts you can just clearTimeout(this.timeoutId) so this function never fires.

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

Successfully merging this pull request may close these issues.

3 participants