diff --git a/docs/suspensive.org/src/content/en/docs/react/ErrorBoundary.mdx b/docs/suspensive.org/src/content/en/docs/react/ErrorBoundary.mdx index a3b3f99ad..02ecc1d02 100644 --- a/docs/suspensive.org/src/content/en/docs/react/ErrorBoundary.mdx +++ b/docs/suspensive.org/src/content/en/docs/react/ErrorBoundary.mdx @@ -298,11 +298,11 @@ export const fetchSomething = () => { -### props.onError +### props.onCatch This is a callback called when `` catches an error. -```tsx /onError/ +```tsx /onCatch/ import { ErrorBoundary } from '@suspensive/react' const logError = (error: Error, info: ErrorInfo) => { @@ -310,7 +310,7 @@ const logError = (error: Error, info: ErrorInfo) => { } const Example = ( - + ) @@ -335,7 +335,7 @@ export const Example = () => { {props.error.message} )} - onError={logError} + onCatch={logError} > diff --git a/docs/suspensive.org/src/content/en/docs/react/migration/_meta.tsx b/docs/suspensive.org/src/content/en/docs/react/migration/_meta.tsx index 7ca932882..e3b2a482a 100644 --- a/docs/suspensive.org/src/content/en/docs/react/migration/_meta.tsx +++ b/docs/suspensive.org/src/content/en/docs/react/migration/_meta.tsx @@ -1,6 +1,7 @@ import type { MetaRecord } from 'nextra' export default { + 'migrate-to-v4': { title: 'Migrate to v4' }, 'migrate-to-v3': { title: 'Migrate to v3' }, 'migrate-to-v2': { title: 'Migrate to v2' }, } satisfies MetaRecord diff --git a/docs/suspensive.org/src/content/en/docs/react/migration/migrate-to-v4.mdx b/docs/suspensive.org/src/content/en/docs/react/migration/migrate-to-v4.mdx new file mode 100644 index 000000000..efd600eec --- /dev/null +++ b/docs/suspensive.org/src/content/en/docs/react/migration/migrate-to-v4.mdx @@ -0,0 +1,55 @@ +# Migrating to v4 + +## Handling BREAKING CHANGES + +### ErrorBoundary's `onError` prop renamed to `onCatch` [#1783](https://github.com/toss/suspensive/issues/1783) + +The `onError` prop in `ErrorBoundary` has been renamed to `onCatch` to better align with React's naming conventions and improve API consistency. + +This change makes the API more intuitive by matching the naming pattern: + +- `shouldCatch` - determines whether to catch the error +- `componentDidCatch` - React lifecycle method that catches the error +- `onCatch` - callback invoked when an error is caught + +#### Migration + +Simply rename the `onError` prop to `onCatch`: + +```diff + import { ErrorBoundary } from '@suspensive/react' + + const logError = (error: Error, info: ErrorInfo) => { + console.log(error, info) + } + + const Example = () => ( + ( + <> + + {props.error.message} + + )} +- onError={logError} ++ onCatch={logError} + > + + + ) +``` + +This change also applies when using `ErrorBoundary.with`: + +```diff + import { ErrorBoundary } from '@suspensive/react' + + const Example = ErrorBoundary.with( + { + fallback: ({ error }) => <>{error.message}, +- onError: logger.log, ++ onCatch: logger.log, + }, + YourComponent + ) +``` diff --git a/docs/suspensive.org/src/content/ko/docs/react/ErrorBoundary.mdx b/docs/suspensive.org/src/content/ko/docs/react/ErrorBoundary.mdx index bbe8afb8f..57c46519f 100644 --- a/docs/suspensive.org/src/content/ko/docs/react/ErrorBoundary.mdx +++ b/docs/suspensive.org/src/content/ko/docs/react/ErrorBoundary.mdx @@ -301,11 +301,11 @@ export const fetchSomething = () => { -### props.onError +### props.onCatch ``가 error를 잡을 때 호출되는 callback입니다. -```tsx /onError/ +```tsx /onCatch/ import { ErrorBoundary } from '@suspensive/react' const logError = (error: Error, info: ErrorInfo) => { @@ -313,7 +313,7 @@ const logError = (error: Error, info: ErrorInfo) => { } const Example = ( - + ) @@ -338,7 +338,7 @@ export const Example = () => { {props.error.message} )} - onError={logError} + onCatch={logError} > diff --git a/docs/suspensive.org/src/content/ko/docs/react/migration/_meta.tsx b/docs/suspensive.org/src/content/ko/docs/react/migration/_meta.tsx index c2225a598..943e40d1e 100644 --- a/docs/suspensive.org/src/content/ko/docs/react/migration/_meta.tsx +++ b/docs/suspensive.org/src/content/ko/docs/react/migration/_meta.tsx @@ -2,6 +2,7 @@ import type { MetaRecord } from 'nextra' import type MetaEn from '../../../../en/docs/react/migration/_meta' export default { + 'migrate-to-v4': { title: 'v4로 마이그레이션하기' }, 'migrate-to-v3': { title: 'v3로 마이그레이션하기' }, 'migrate-to-v2': { title: 'v2로 마이그레이션하기' }, } satisfies typeof MetaEn satisfies MetaRecord diff --git a/docs/suspensive.org/src/content/ko/docs/react/migration/migrate-to-v4.mdx b/docs/suspensive.org/src/content/ko/docs/react/migration/migrate-to-v4.mdx new file mode 100644 index 000000000..7921d649f --- /dev/null +++ b/docs/suspensive.org/src/content/ko/docs/react/migration/migrate-to-v4.mdx @@ -0,0 +1,55 @@ +# v4로 마이그레이션하기 + +## BREAKING CHANGES 처리하기 + +### ErrorBoundary의 `onError` prop이 `onCatch`로 이름 변경 [#1783](https://github.com/toss/suspensive/issues/1783) + +`ErrorBoundary`의 `onError` prop이 React의 네이밍 컨벤션에 더 잘 맞추고 API 일관성을 개선하기 위해 `onCatch`로 이름이 변경되었습니다. + +이 변경으로 네이밍 패턴이 일치하여 API가 더 직관적이 됩니다: + +- `shouldCatch` - 에러를 캐치할지 결정합니다 +- `componentDidCatch` - 에러를 캐치하는 React 생명주기 메서드 +- `onCatch` - 에러가 캐치될 때 호출되는 콜백 + +#### 마이그레이션 + +`onError` prop을 `onCatch`로 이름만 변경하면 됩니다: + +```diff + import { ErrorBoundary } from '@suspensive/react' + + const logError = (error: Error, info: ErrorInfo) => { + console.log(error, info) + } + + const Example = () => ( + ( + <> + + {props.error.message} + + )} +- onError={logError} ++ onCatch={logError} + > + + + ) +``` + +`ErrorBoundary.with`를 사용할 때도 동일하게 적용됩니다: + +```diff + import { ErrorBoundary } from '@suspensive/react' + + const Example = ErrorBoundary.with( + { + fallback: ({ error }) => <>{error.message}, +- onError: logger.log, ++ onCatch: logger.log, + }, + YourComponent + ) +``` diff --git a/examples/visualization/src/app/react/wrap/page.tsx b/examples/visualization/src/app/react/wrap/page.tsx index 04af7426a..c490c55ef 100644 --- a/examples/visualization/src/app/react/wrap/page.tsx +++ b/examples/visualization/src/app/react/wrap/page.tsx @@ -7,7 +7,7 @@ const logError = (error: Error) => console.error(error) export default ErrorBoundaryGroup.with( { blockOutside: false }, ErrorBoundary.with( - { fallback: (props) =>
{props.error.message}
, onError: logError }, + { fallback: (props) =>
{props.error.message}
, onCatch: logError }, Suspense.with({ clientOnly: true, fallback: 'loading...' }, ({ text }: { text: string }) => { const errorBoundary = useErrorBoundary() diff --git a/examples/vite-react-18-suspense-prerender-siblings-problem/tsconfig.tsbuildinfo b/examples/vite-react-18-suspense-prerender-siblings-problem/tsconfig.tsbuildinfo index 832ae3958..6270cb2ff 100644 --- a/examples/vite-react-18-suspense-prerender-siblings-problem/tsconfig.tsbuildinfo +++ b/examples/vite-react-18-suspense-prerender-siblings-problem/tsconfig.tsbuildinfo @@ -1 +1 @@ -{"root":["./src/App.tsx","./src/main.tsx","./src/vite-env.d.ts","./vite.config.ts"],"version":"5.8.3"} \ No newline at end of file +{"root":["./src/App.tsx","./src/main.tsx","./src/vite-env.d.ts","./vite.config.ts"],"version":"5.9.2"} \ No newline at end of file diff --git a/packages/react/src/ErrorBoundary.spec.tsx b/packages/react/src/ErrorBoundary.spec.tsx index 3ea52a297..91e304d3f 100644 --- a/packages/react/src/ErrorBoundary.spec.tsx +++ b/packages/react/src/ErrorBoundary.spec.tsx @@ -20,11 +20,11 @@ describe('', () => { Throw.reset() }) - it('should show children if no error but if error in children, catch it and show fallback and call onError', async () => { - const onError = vi.fn() + it('should show children if no error but if error in children, catch it and show fallback and call onCatch', async () => { + const onCatch = vi.fn() render( - {FALLBACK}}> + {FALLBACK}}> {TEXT} @@ -33,11 +33,11 @@ describe('', () => { expect(screen.queryByText(TEXT)).toBeInTheDocument() expect(screen.queryByText(FALLBACK)).not.toBeInTheDocument() - expect(onError).toHaveBeenCalledTimes(0) + expect(onCatch).toHaveBeenCalledTimes(0) await act(() => vi.advanceTimersByTime(100)) expect(screen.queryByText(FALLBACK)).toBeInTheDocument() expect(screen.queryByText(TEXT)).not.toBeInTheDocument() - expect(onError).toHaveBeenCalledTimes(1) + expect(onCatch).toHaveBeenCalledTimes(1) }) it('should show children if no error but if error in children, catch it and show fallback component', async () => { @@ -67,21 +67,21 @@ describe('', () => { }) it('should catch it even if thrown null', async () => { - const onError = vi.fn() + const onCatch = vi.fn() render( - {FALLBACK}}> + {FALLBACK}}> {TEXT} ) expect(screen.queryByText(TEXT)).toBeInTheDocument() expect(screen.queryByText(FALLBACK)).not.toBeInTheDocument() - expect(onError).toHaveBeenCalledTimes(0) + expect(onCatch).toHaveBeenCalledTimes(0) await act(() => vi.advanceTimersByTime(100)) expect(screen.queryByText(FALLBACK)).toBeInTheDocument() expect(screen.queryByText(TEXT)).not.toBeInTheDocument() - expect(onError).toHaveBeenCalledTimes(1) + expect(onCatch).toHaveBeenCalledTimes(1) }) it('should be reset by items of resetKeys, and call onReset', async () => { @@ -193,15 +193,15 @@ describe('', () => { }) it('should catch Error by many criteria', () => { - const onErrorParent = vi.fn() - const onErrorChild = vi.fn() + const onCatchParent = vi.fn() + const onCatchChild = vi.fn() render( - <>{error.message} of Parent} onError={onErrorParent}> + <>{error.message} of Parent} onCatch={onCatchParent}> error instanceof CustomError]} fallback={({ error }) => <>{error.message} of Child} - onError={onErrorChild} + onCatch={onCatchChild} > {createElement(() => { throw new CustomError(ERROR_MESSAGE) @@ -210,19 +210,19 @@ describe('', () => { ) - expect(onErrorChild).toBeCalledTimes(1) - expect(onErrorParent).toBeCalledTimes(0) + expect(onCatchChild).toBeCalledTimes(1) + expect(onCatchParent).toBeCalledTimes(0) expect(screen.queryByText(`${ERROR_MESSAGE} of Child`)).toBeInTheDocument() }) it('should re-throw error if not shouldCatch error in children without rendering fallback', () => { - const onErrorParent = vi.fn() - const onErrorChild = vi.fn() + const onCatchParent = vi.fn() + const onCatchChild = vi.fn() const Fallback = vi.fn() render( - <>{error.message} of Parent} onError={onErrorParent}> - + <>{error.message} of Parent} onCatch={onCatchParent}> + {createElement(() => { throw new Error(ERROR_MESSAGE) })} @@ -230,8 +230,8 @@ describe('', () => { ) - expect(onErrorChild).toBeCalledTimes(0) - expect(onErrorParent).toBeCalledTimes(1) + expect(onCatchChild).toBeCalledTimes(0) + expect(onCatchParent).toBeCalledTimes(1) expect(screen.queryByText(`${ERROR_MESSAGE} of Parent`)).toBeInTheDocument() }) @@ -251,15 +251,15 @@ describe('', () => { ])( 'should catch Error by one criteria(ErrorConstructor)', ({ childCalledTimes, parentCalledTimes, shouldCatch, errorText }) => { - const onErrorParent = vi.fn() - const onErrorChild = vi.fn() + const onCatchParent = vi.fn() + const onCatchChild = vi.fn() render( - <>{error.message} of Parent} onError={onErrorParent}> + <>{error.message} of Parent} onCatch={onCatchParent}> <>{error.message} of Child} - onError={onErrorChild} + onCatch={onCatchChild} > {createElement(() => { throw new Error(ERROR_MESSAGE) @@ -268,8 +268,8 @@ describe('', () => { ) - expect(onErrorChild).toBeCalledTimes(childCalledTimes) - expect(onErrorParent).toBeCalledTimes(parentCalledTimes) + expect(onCatchChild).toBeCalledTimes(childCalledTimes) + expect(onCatchParent).toBeCalledTimes(parentCalledTimes) expect(screen.queryByText(errorText)).toBeInTheDocument() } ) @@ -290,15 +290,15 @@ describe('', () => { ])( 'should catch Error by one criteria(ShouldCatchCallback)', ({ childCalledTimes, parentCalledTimes, shouldCatch, errorText }) => { - const onErrorParent = vi.fn() - const onErrorChild = vi.fn() + const onCatchParent = vi.fn() + const onCatchChild = vi.fn() render( - <>{error.message} of Parent} onError={onErrorParent}> + <>{error.message} of Parent} onCatch={onCatchParent}> <>{error.message} of Child} - onError={onErrorChild} + onCatch={onCatchChild} > {createElement(() => { throw new Error(ERROR_MESSAGE) @@ -307,8 +307,8 @@ describe('', () => { ) - expect(onErrorChild).toBeCalledTimes(childCalledTimes) - expect(onErrorParent).toBeCalledTimes(parentCalledTimes) + expect(onCatchChild).toBeCalledTimes(childCalledTimes) + expect(onCatchParent).toBeCalledTimes(parentCalledTimes) expect(screen.queryByText(errorText)).toBeInTheDocument() } ) @@ -319,15 +319,15 @@ describe('', () => { ])( 'should catch Error by one criteria(boolean)', ({ childCalledTimes, parentCalledTimes, errorText, shouldCatch }) => { - const onErrorParent = vi.fn() - const onErrorChild = vi.fn() + const onCatchParent = vi.fn() + const onCatchChild = vi.fn() render( - <>{error.message} of Parent} onError={onErrorParent}> + <>{error.message} of Parent} onCatch={onCatchParent}> <>{error.message} of Child} - onError={onErrorChild} + onCatch={onCatchChild} > {createElement(() => { throw new Error(ERROR_MESSAGE) @@ -336,8 +336,8 @@ describe('', () => { ) - expect(onErrorChild).toBeCalledTimes(childCalledTimes) - expect(onErrorParent).toBeCalledTimes(parentCalledTimes) + expect(onCatchChild).toBeCalledTimes(childCalledTimes) + expect(onCatchParent).toBeCalledTimes(parentCalledTimes) expect(screen.queryByText(errorText)).toBeInTheDocument() } ) @@ -421,11 +421,11 @@ describe('useErrorBoundary', () => { }) it('should supply setError to set Error of ErrorBoundary manually', async () => { - const onError = vi.fn() + const onCatch = vi.fn() render( { expect(screen.queryByText(TEXT)).toBeInTheDocument() expect(screen.queryByText(ERROR_MESSAGE)).not.toBeInTheDocument() - expect(onError).toHaveBeenCalledTimes(0) + expect(onCatch).toHaveBeenCalledTimes(0) await act(() => vi.advanceTimersByTime(100)) expect(screen.queryByText(ERROR_MESSAGE)).toBeInTheDocument() expect(screen.queryByText(TEXT)).not.toBeInTheDocument() - expect(onError).toHaveBeenCalledTimes(1) + expect(onCatch).toHaveBeenCalledTimes(1) }) it('should guarantee hook calling position is in children of ErrorBoundary', () => { diff --git a/packages/react/src/ErrorBoundary.test-d.tsx b/packages/react/src/ErrorBoundary.test-d.tsx index c7b623110..24d271d73 100644 --- a/packages/react/src/ErrorBoundary.test-d.tsx +++ b/packages/react/src/ErrorBoundary.test-d.tsx @@ -108,7 +108,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -126,7 +126,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -145,7 +145,7 @@ describe('', () => { const example = ( isAnotherError(e), isAnotherError, (e) => e instanceof AnotherError]} - onError={(error) => { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -185,7 +185,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -204,7 +204,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -223,7 +223,7 @@ describe('', () => { const example = ( } - onError={(error) => { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf>() }} fallback={({ error }) => { @@ -244,7 +244,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -262,7 +262,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -280,7 +280,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -299,7 +299,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -318,7 +318,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -342,7 +342,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -370,7 +370,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -394,7 +394,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -422,7 +422,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -440,7 +440,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -475,7 +475,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -521,7 +521,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -540,7 +540,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -560,7 +560,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -578,7 +578,7 @@ describe('', () => { const example = ( { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf() }} fallback={({ error }) => { @@ -602,7 +602,7 @@ describe('', () => { const example = ( ]} - onError={(error) => { + onCatch={(error) => { expectTypeOf(error).toEqualTypeOf>() }} fallback={({ error }) => { @@ -690,7 +690,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: CustomError, - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -709,7 +709,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: CustomError, - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -729,7 +729,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [CustomError, (e) => isAnotherError(e), isAnotherError, (e) => e instanceof AnotherError], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -771,7 +771,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: AnotherError, - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -791,7 +791,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: ThirdError, - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -811,7 +811,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: FifthError, - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf>() }, fallback: ({ error }) => { @@ -833,7 +833,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: isAnotherError, - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -852,7 +852,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: isAnotherErrorWithErrorParam, - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -871,7 +871,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: isThirdError, - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -891,7 +891,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: customErrorCallback, - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -911,7 +911,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [CustomError, AnotherError], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -936,7 +936,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [CustomError, AnotherError, ThirdError], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -965,7 +965,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [CustomError, isAnotherError], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -990,7 +990,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [isAnotherError, isThirdError, isFourthError], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -1019,7 +1019,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [CustomError, customErrorCallback], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -1038,7 +1038,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [CustomError, true], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -1075,7 +1075,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [CustomError, AnotherError, isThirdError, isFourthError], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -1123,7 +1123,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [CustomError], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -1143,7 +1143,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [isAnotherError], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -1164,7 +1164,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: Error, - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -1183,7 +1183,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [Error, CustomError, AnotherError], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf() }, fallback: ({ error }) => { @@ -1208,7 +1208,7 @@ describe('', () => { const WrappedComponent = ErrorBoundary.with( { shouldCatch: [CustomError, FifthError], - onError: (error) => { + onCatch: (error) => { expectTypeOf(error).toEqualTypeOf>() }, fallback: ({ error }) => { diff --git a/packages/react/src/ErrorBoundary.tsx b/packages/react/src/ErrorBoundary.tsx index a93683c9f..e88acaaea 100644 --- a/packages/react/src/ErrorBoundary.tsx +++ b/packages/react/src/ErrorBoundary.tsx @@ -99,9 +99,9 @@ export type ErrorBoundaryProps = PropsW */ onReset?: () => void /** - * when ErrorBoundary catch error, onError will be triggered + * when ErrorBoundary catch error, onCatch will be triggered */ - onError?: (error: InferError, info: ErrorInfo) => void + onCatch?: (error: InferError, info: ErrorInfo) => void /** * when ErrorBoundary catch error, fallback will be render instead of children */ @@ -147,7 +147,7 @@ class BaseErrorBoundary extends Component< } componentDidCatch(error: InferError, info: ErrorInfo) { - this.props.onError?.(error, info) + this.props.onCatch?.(error, info) } reset = () => { @@ -221,7 +221,7 @@ export const ErrorBoundary = Object.assign( props: ErrorBoundaryProps, ref: ForwardedRef ) { - const { fallback, children, onError, onReset, resetKeys, shouldCatch } = props + const { fallback, children, onCatch, onReset, resetKeys, shouldCatch } = props const group = useContext(ErrorBoundaryGroupContext) ?? { resetKey: 0 } const baseErrorBoundaryRef = useRef>(null) useImperativeHandle(ref, () => ({ @@ -232,7 +232,7 @@ export const ErrorBoundary = Object.assign( shouldCatch={shouldCatch} fallback={fallback} - onError={onError} + onCatch={onCatch} onReset={onReset} resetKeys={[group.resetKey, ...(resetKeys || [])]} ref={baseErrorBoundaryRef}