Skip to content

Commit

Permalink
render children from props instead of state Cc: Sebastian Cruz @Sebas…
Browse files Browse the repository at this point in the history
  • Loading branch information
zekchan committed Apr 2, 2019
1 parent 7978843 commit 35442b3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ export function withContext (contextTypes = {}) {
}
static contextTypes = contextTypes
state = {
elementToRender: this.props.children
hasError: false
}

componentDidCatch () {
this.setState({
elementToRender: this.props.fallBack()
hasError: true
})
}

render () {
if (server) return server._render(this, ProvideContext)
return <div>{this.state.elementToRender}</div>
return <div>{this.state.hasError ? this.props.fallBack() : this.props.children}</div>
}
}

Expand Down

0 comments on commit 35442b3

Please sign in to comment.