Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Error handling #452

Open
istarkov opened this issue Jul 27, 2017 · 1 comment
Open

Error handling #452

istarkov opened this issue Jul 27, 2017 · 1 comment

Comments

@istarkov
Copy link
Contributor

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.

@mcky
Copy link

mcky commented Jul 28, 2017

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants