Skip to content

Commit

Permalink
fix: React 16.3 compatibility
Browse files Browse the repository at this point in the history
Closes #57
  • Loading branch information
gregberge committed Apr 5, 2018
1 parent 96333ca commit abd7963
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/loadable.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,29 @@ function loadable(
return LoadableComponent.loadingPromise
}

state = {
Component: LoadableComponent.Component,
error: null,
loading: true,
}

mounted = false

componentWillMount() {
if (typeof window === 'undefined' || this.state.Component !== null) return

LoadableComponent.load()
.then(Component => {
this.safeSetState({ Component, loading: false })
})
.catch(error => {
this.safeSetState({ error, loading: false })
})
constructor(props) {
super(props)
this.state = {
Component: LoadableComponent.Component,
error: null,
loading: true,
}
this.mounted = false
this.loadingPromise = null

if (
typeof window !== 'undefined' &&
this.state.Component === null &&
this.loadingPromise === null
) {
this.loadingPromise = LoadableComponent.load()
.then(Component => {
this.safeSetState({ Component, loading: false })
})
.catch(error => {
this.safeSetState({ error, loading: false })
})
}
}

componentDidMount() {
Expand Down

0 comments on commit abd7963

Please sign in to comment.