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

Provide fallback #6

Open
havenchyk opened this issue Dec 12, 2016 · 2 comments
Open

Provide fallback #6

havenchyk opened this issue Dec 12, 2016 · 2 comments

Comments

@havenchyk
Copy link
Contributor

What do you think about possible fallback for component?

E.g. We have 10 components and would like to handle their errors, but not in the same way
(for error in component 1 show notification, for component 2 - red box etc)

So with current interface I don't see the way to make it possible

reactGuard(React, function (err, componentInfo) {
  return <div>Failed to render</div>
})

Possible solutions are:

  1. pass the class itself as a part of componentInfo (with static method that implements fallback)
  2. pass the class itself as a third parameter

@kossnocorp what do you think? maybe you have better idea?

@kossnocorp
Copy link
Owner

You can rely on displayName and put a condition to the guard function. Is it not enough? It would be helpful if you'll provide an extended example.

@havenchyk
Copy link
Contributor Author

havenchyk commented Dec 12, 2016

@kossnocorp we can't rely on displayName, because of

  1. it doesn't work for createClass
  2. it doesn't work for functional components

But to my mind we can do something like this

class MyComponent extends React.Component {
  static guardFallback() {
    return <SomeSpecificJSX />
  }

  render() {
    throw new Error('some error')
  }
}

and handle error

reactGuard(React, function (err, componentInfo, ComponentClass) {
  if (ComponentClass.guardFallback) {
    return ComponentClass.guardFallback()
  }

  return <div>Failed to render</div>
})

it's just a suggestion, so your opinion is highly appreciated

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

No branches or pull requests

2 participants