Skip to content

Commit

Permalink
fix call setState on an unmounted component
Browse files Browse the repository at this point in the history
  • Loading branch information
Wonday committed May 15, 2018
1 parent 4127535 commit 31fcd28
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions PdfView.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,27 @@ export default class PdfView extends Component {
this.flatList = null;
this.scaleTimer = null;
this.scrollTimer = null;
this.mounted = false;

}

componentWillMount() {
}

componentDidMount() {

this.mounted = true;
PdfManager.loadFile(this.props.path, this.props.password)
.then((pdfInfo) => {
this.setState({
pdfLoaded: true,
fileNo: pdfInfo[0],
numberOfPages: pdfInfo[1],
pageAspectRate: pdfInfo[3] === 0 ? 1 : pdfInfo[2] / pdfInfo[3]
});
if (this.props.onLoadComplete) this.props.onLoadComplete(pdfInfo[1], this.props.path);
if (this.mounted) {
this.setState({
pdfLoaded: true,
fileNo: pdfInfo[0],
numberOfPages: pdfInfo[1],
pageAspectRate: pdfInfo[3] === 0 ? 1 : pdfInfo[2] / pdfInfo[3]
});
if (this.props.onLoadComplete) this.props.onLoadComplete(pdfInfo[1], this.props.path);
}

})
.catch((error) => {
this.props.onError(error);
Expand Down Expand Up @@ -117,7 +121,7 @@ export default class PdfView extends Component {
}

componentWillUnmount() {

this.mounted = false;
clearTimeout(this.scaleTimer);
clearTimeout(this.scrollTimer);

Expand Down

0 comments on commit 31fcd28

Please sign in to comment.