AsyncBoundary (deprecated)
deprecated: <Suspense/>
, <ErrorBoundary/>
์ ์ง์ ์ฌ์ฉํ์ธ์
<AsyncBoundary/>
์ @suspensive/react์ <Suspense/>
์ <ErrorBoundary/>
์ ํ๋ฒ์ ์ฌ์ฉํ๊ธฐ ์ํด ๋ํํ ์ปดํฌ๋ํธ์
๋๋ค.
import { AsyncBoundary } from '@suspensive/react'
const Example = () => (
<AsyncBoundary
pendingFallback={<Loading />}
rejectedFallback={(props) => (
<>
<button onClick={props.reset}>Try again</button>
{props.error.message}
</>
)}
onReset={() => console.log('reset')}
onError={(error) => console.log(error)}
>
<Children />
</AsyncBoundary>
)
AsyncBoundaryProps
deprecated: SuspenseProps, ErrorBoundaryProps์ ์ง์ ์ฌ์ฉํ์ธ์
<AsyncBoundary/>
Props์ ํ์
์ <Suspense/>
์ <ErrorBoundary/>
๋ฅผ ์กฐํฉํฉ๋๋ค.
type AsyncBoundaryProps = Omit<SuspenseProps, 'fallback'> &
Omit<ErrorBoundaryProps, 'fallback'> & {
pendingFallback?: SuspenseProps['fallback']
rejectedFallback: ErrorBoundaryProps['fallback']
}
withAsyncBoundary
deprecated: wrap.ErrorBoundary().Suspense().on์ ๋์ ์ฌ์ฉํ์ธ์
withAsyncBoundary๋ฅผ ์ฌ์ฉํ๋ฉด ์ปดํฌ๋ํธ๋ฅผ <AsyncBoundary/>
๋ก ์ฝ๊ฒ ๋ํํ ์ ์์ต๋๋ค.
์๋์ ๊ฐ์ด withAsyncBoundary๋ฅผ ์ฌ์ฉํ๋ฉด ์ด๋ฅผ ๊ฐ์ธ๊ธฐ ์ํด ๋ถํ์ํ ์ฝ๋๋ฅผ ๋ง๋ค ํ์๊ฐ ์์ต๋๋ค.
withAsyncBoundary์ ๋ ๋ฒ์งธ ์ธ์๋ children์ด ์๋ <AsyncBoundary/>
์ props์
๋๋ค.
import { withAsyncBoundary } from '@suspensive/react'
const Example = withAsyncBoundary(
function Component() {
return <>...</>
},
{
pendingFallback: <Loading />,
rejectedFallback: (props) => (
<>
<button onClick={props.reset}>Try again</button>
{props.error.message}
</>
),
onReset: () => console.log('reset'),
onError: (error) => console.log(error),
}
)