malte-wessel / react-textfit

React component to fit headlines and paragraphs into elements
http://malte-wessel.github.io/react-textfit/
MIT License
470 stars 143 forks source link

Resizing window gives warnings to console #15

Closed jepaavol closed 7 years ago

jepaavol commented 7 years ago

When browser window is resized it seems that component still calls setState once it has been unmounted. This causes error prints to console: Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the Textfit component.

Problematic code part is this. ], err => { // err will be true, if another process was triggered if (err) return; this.setState({ ready: true }, () => onReady(mid)); }); Issue gets fixed if shouldCancelProcess is checked before state is updated like this: ], err => { // err will be true, if another process was triggered if (err || shouldCancelProcess()) return; this.setState({ ready: true }, () => onReady(mid)); });