-
Notifications
You must be signed in to change notification settings - Fork 52
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
feat(react): add useErrorBoundaryFallbackProps #216
Conversation
🦋 Changeset detectedLatest commit: 5d72fb0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov Report
@@ Coverage Diff @@
## main #216 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 21 21
Lines 829 842 +13
Branches 146 149 +3
=========================================
+ Hits 829 842 +13
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this hook is very convenient, but how about provide props type guide like this?
import { ErrorBoundaryFallbackProps } from '@suspensive/react'
const Nested = ({ reset, error }: ErrorBoundaryFallbackProps) => {
return (
<>
<button onClick={reset}>reset</button>
{error.message}
</>
)
}
This is exactly same, but can't avoid props drilling.
So, my suggestion is, before provide example that can avoid props drilling case, first show simple example.
And How about add Errorboundary component's visualization page and link it?
hundred words are worth a glance. In korea 백문이불여일견
Co-authored-by: 김석진 <[email protected]>
Co-authored-by: 김석진 <[email protected]>
Co-authored-by: 김석진 <[email protected]>
@minsoo-web could you add suggestion code or Pull Request to this branch please? I want to know what your intend exactly |
I made PR for this case #221 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I referenced to #221, how about this for document commonization?
* docs(errorboundary): change & add example case for ErrorBoundary * docs(react/errorboundary): change & add example case to ErrorBoundary (en) * docs(react): suggestion to advise/useErrorBoundaryProps (#227) * Update ErrorBoundary.ko.mdx Co-authored-by: Jonghyeon Ko <[email protected]> * Update ErrorBoundary.en.mdx Co-authored-by: Jonghyeon Ko <[email protected]> --------- Co-authored-by: Jonghyeon Ko <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
import type { ErrorBoundaryFallbackProps } from '@suspensive/react' | ||
|
||
const ErrorBoundaryFallback = ({ reset, error }: ErrorBoundaryFallbackProps) => ( | ||
<> | ||
<button onClick={reset}>reset</button> | ||
{error.message} | ||
</> | ||
) | ||
|
||
const Example = () => ( | ||
<ErrorBoundary fallback={ErrorBoundaryFallback}> | ||
<ErrorAfter4s /> | ||
</ErrorBoundary> | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's for the purpose of providing typing
Wouldn't it be better for the developer experience to define not only the type of props but also the return?
import type { ErrorBoundaryFallbackProps } from '@suspensive/react' | |
const ErrorBoundaryFallback = ({ reset, error }: ErrorBoundaryFallbackProps) => ( | |
<> | |
<button onClick={reset}>reset</button> | |
{error.message} | |
</> | |
) | |
const Example = () => ( | |
<ErrorBoundary fallback={ErrorBoundaryFallback}> | |
<ErrorAfter4s /> | |
</ErrorBoundary> | |
) | |
import type { ErrorBoundaryFallbackType } from '@suspensive/react' | |
const ErrorBoundaryFallback: ErrorBoundaryFallbackType = ({ reset, error }) => ( | |
<> // The type of return value is also certain | |
<button onClick={reset}>reset</button> | |
{error.message} | |
</> | |
) | |
const Example = () => ( | |
<ErrorBoundary fallback={ErrorBoundaryFallback}> | |
<ErrorAfter4s /> | |
</ErrorBoundary> | |
) |
I inspried by nextjs GetServerSideProps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better for the developer experience to define not only the type of props but also the return?
I think that's a good idea too. However, even if we do not provide the return type, TypeScript will create a type error if it does not match the fallback type of ErrorBoundary.
I think we need to consider whether providing a return type is right choice. Because the return type may be different from the actual thing returned (this video explain it well). If it is as essential as ErrorBoundaryFallbackProps, it would be a good idea to add it as a minor version feature.
Let's consider it after merging this
* feat(react): add useErrorBoundaryFallbackProps * chore: update * Create two-weeks-serve.md * Update packages/react/src/ErrorBoundary.ko.mdx Co-authored-by: 김석진 <[email protected]> * Update packages/react/src/ErrorBoundary.ko.mdx Co-authored-by: 김석진 <[email protected]> * Update packages/react/src/ErrorBoundary.ko.mdx Co-authored-by: 김석진 <[email protected]> * docs: update * Update packages/react/src/ErrorBoundary.ko.mdx Co-authored-by: 김석진 <[email protected]> * Update packages/react/src/ErrorBoundary.en.mdx Co-authored-by: 김석진 <[email protected]> * advise(react/errorboundary): add & change example case (#221) * docs(errorboundary): change & add example case for ErrorBoundary * docs(react/errorboundary): change & add example case to ErrorBoundary (en) * docs(react): suggestion to advise/useErrorBoundaryProps (#227) * Update ErrorBoundary.ko.mdx Co-authored-by: Jonghyeon Ko <[email protected]> * Update ErrorBoundary.en.mdx Co-authored-by: Jonghyeon Ko <[email protected]> --------- Co-authored-by: Jonghyeon Ko <[email protected]> --------- Co-authored-by: 김석진 <[email protected]> Co-authored-by: 김민수 <[email protected]>
* feat(react): add useErrorBoundaryFallbackProps * chore: update * Create two-weeks-serve.md * Update packages/react/src/ErrorBoundary.ko.mdx * Update packages/react/src/ErrorBoundary.ko.mdx * Update packages/react/src/ErrorBoundary.ko.mdx * docs: update * Update packages/react/src/ErrorBoundary.ko.mdx * Update packages/react/src/ErrorBoundary.en.mdx * advise(react/errorboundary): add & change example case (#221) * docs(errorboundary): change & add example case for ErrorBoundary * docs(react/errorboundary): change & add example case to ErrorBoundary (en) * docs(react): suggestion to advise/useErrorBoundaryProps (#227) * Update ErrorBoundary.ko.mdx * Update ErrorBoundary.en.mdx --------- ---------
* feat(react): add useErrorBoundaryFallbackProps * chore: update * Create two-weeks-serve.md * Update packages/react/src/ErrorBoundary.ko.mdx Co-authored-by: 김석진 <[email protected]> * Update packages/react/src/ErrorBoundary.ko.mdx Co-authored-by: 김석진 <[email protected]> * Update packages/react/src/ErrorBoundary.ko.mdx Co-authored-by: 김석진 <[email protected]> * docs: update * Update packages/react/src/ErrorBoundary.ko.mdx Co-authored-by: 김석진 <[email protected]> * Update packages/react/src/ErrorBoundary.en.mdx Co-authored-by: 김석진 <[email protected]> * advise(react/errorboundary): add & change example case (#221) * docs(errorboundary): change & add example case for ErrorBoundary * docs(react/errorboundary): change & add example case to ErrorBoundary (en) * docs(react): suggestion to advise/useErrorBoundaryProps (#227) * Update ErrorBoundary.ko.mdx Co-authored-by: Jonghyeon Ko <[email protected]> * Update ErrorBoundary.en.mdx Co-authored-by: Jonghyeon Ko <[email protected]> --------- Co-authored-by: Jonghyeon Ko <[email protected]> --------- Co-authored-by: 김석진 <[email protected]> Co-authored-by: 김민수 <[email protected]>
related with #200
Overview
I added useErrorBoundaryFallbackProps to make useErrorBoundary don't have role in fallback of
<ErrorBoundary/>
Cause of adding useErrorBoundaryFallbackProps
<ErrorBoundary/>
, but actually runtimely it's not.<ErrorBoundary/>
, but actually runtimely there must have error in fallback of<ErrorBoundary/>
<ErrorBoundary/>
, but it didn't work in children because there is no error to reset in children of<ErrorBoundary/>
.Solution
I think both children / fallback of
<ErrorBoundary/>
should have separate hook for each section. so I made useErrorBoundaryFallbackProps separate from useErrorBoundary<ErrorBoundary/>
)<ErrorBoundary/>
)PR Checklist