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

error boundaries #257

Open
jantimon opened this issue Apr 19, 2021 · 2 comments
Open

error boundaries #257

jantimon opened this issue Apr 19, 2021 · 2 comments

Comments

@jantimon
Copy link

does/will fre support error boundaries?

@yisar
Copy link
Collaborator

yisar commented Apr 19, 2021

Fre does not support error boundaries yet, but there are plans to support them in the future, because ErrorBoundary is similar to Suspense, and takes advantage of the fallback feature of the fiber linked list.

@yisar
Copy link
Collaborator

yisar commented Apr 19, 2021

@jantimon hi, I am back. According to your issue, I implement this in fre, but it's worth noting that it's different from the API of react16.

import { ErrorBoundary } from 'fre'

function errorFn(error){
  console.error(error)
  return <div>hello</div>
}

function App() {
  return <ErrorBoundary fallback={errorFn}>
    <A/>
  </ErrorBoundary>
}

function A(){
  throw 111
}

Fre's ErrorBoundary is more like Suspense, it has a fallback props, which takes advantage of the fallback feature of linked list

https://github.com/preactjs/preact/blob/master/hooks/src/index.js#L271

I also see that preact has a hooks API, but I don't think it's appropriate. Although it can catch errors, it doesn't conform to the semantics of fallback and boundary.

Which do you think is better?

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