logtrace / material-icons-react

Google material icons implementation for React
MIT License
24 stars 16 forks source link

Component tries to set state after unmount #46

Open erasmo-marin opened 5 years ago

erasmo-marin commented 5 years ago

I'm getting this warning on my app:

index.js:1437 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.

This is caused because MaterialIcon loads the font and after that set it in state in the onFontActive function:

https://github.com/logtrace/material-icons-react/blob/develop/src/index.js#L36

At this point, is possible that the component is not mounted, causing the warning. The font load should be cancelled on componentWillUnmount.