pablosichert / react-truncate

React component for truncating multi-line spans and adding an ellipsis.
https://www.webpackbin.com/bins/-Kw6QnAkjmv1OD6Of-ZD
ISC License
587 stars 129 forks source link

Fix React warning about state update of unmounted component #136

Open gamtiq opened 4 years ago

gamtiq commented 4 years ago

Hello,

I encountered the following React's warning when running unit tests for a component that is wrapping react-truncate:

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 the componentWillUnmount method.

I researched and found that the problem is related to non-canceled requestAnimationFrame callback which asynchronously calls a function specified in onTruncate prop. The proposed change eliminates the warning.