Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guard for unmounted component when resolving/rejecting the promise #15

Merged
merged 1 commit into from
Jan 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/react-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ class Async extends React.Component {
})
prom.then(
res => {
this.setState({
status: statusTypes.resolved,
value: res
})
if (!this.unmounted) {
this.setState({
status: statusTypes.resolved,
value: res
})
}
},
err => {
this.setState({
status: statusTypes.rejected,
value: err
})
if (!this.unmounted) {
this.setState({
status: statusTypes.rejected,
value: err
})
}
}
)
}
Expand All @@ -47,6 +51,10 @@ class Async extends React.Component {
this.handlePromise(this.props.promise)
}
}
componentWillUnmount () {
this.unmounted = true
}

render () {
const { props, state } = this

Expand Down