Recompose: Error handling

Created on 27 Jul 2017  ·  1Comment  ·  Source: acdlite/recompose

https://facebook.github.io/react/blog/2017/07/26/error-handling-in-react-16.html
Dear recomposers lets think about this feature and may be an enhancer we could provide.

Most helpful comment

I just had a play around too after seeing their <ErrorBoundry> wrapper and came up with something like this, similar to the spinnerWhileLoading example from docs

Edit: not proposing as part of the lib, just one way to do it yourself :)

const showErrorMessage = ErrorComponent =>
  compose(
    lifecycle({
      componentDidCatch(error, errorInfo) {
        this.setState({ error, errorInfo })
      },
    }),
    branch(props => props.error, renderComponent(ErrorComponent)),
  )

/////

import showErrorMessage from '../utils'

const WillThrow = props =>
  <div>
    {props.undefined[0]}
  </div>

const ErrorMessage = () => <h1>Something went wrong.</h1>

const App = props =>
  <div>
    App
    <WillThrow />
  </div>

export default compose(
  showErrorMessage(ErrorMessage)
)(App)

>All comments

I just had a play around too after seeing their <ErrorBoundry> wrapper and came up with something like this, similar to the spinnerWhileLoading example from docs

Edit: not proposing as part of the lib, just one way to do it yourself :)

const showErrorMessage = ErrorComponent =>
  compose(
    lifecycle({
      componentDidCatch(error, errorInfo) {
        this.setState({ error, errorInfo })
      },
    }),
    branch(props => props.error, renderComponent(ErrorComponent)),
  )

/////

import showErrorMessage from '../utils'

const WillThrow = props =>
  <div>
    {props.undefined[0]}
  </div>

const ErrorMessage = () => <h1>Something went wrong.</h1>

const App = props =>
  <div>
    App
    <WillThrow />
  </div>

export default compose(
  showErrorMessage(ErrorMessage)
)(App)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdomigan picture cdomigan  ·  4Comments

rockchalkwushock picture rockchalkwushock  ·  3Comments

uriklar picture uriklar  ·  4Comments

yellowfrogCN picture yellowfrogCN  ·  3Comments

xialvjun picture xialvjun  ·  4Comments