{
- throw error
- }}
+ promiseFn={promiseFn}
pending="Loading"
- success={() => null}
- error={() => errorContent}
- onError={onError}
+ success={() => 'Success'}
+ error={(err) => Error: {(err as Error).message}
}
/>,
)
- await screen.findByText(errorContent)
- expect(onError).toHaveBeenCalledWith(error)
+ await screen.findByText('Error: Sync Error')
})
})
diff --git a/lib/components/AsyncBlock/index.tsx b/lib/components/AsyncBlock/index.tsx
index fd1b20e..ac977a3 100644
--- a/lib/components/AsyncBlock/index.tsx
+++ b/lib/components/AsyncBlock/index.tsx
@@ -92,7 +92,13 @@ export const AsyncBlock = ({
try {
promise = promiseFn(signal)
} catch (e) {
- promise = Promise.reject(e)
+ if (isMounted.current) {
+ if (timer) clearTimeout(timer)
+ setErr(e)
+ setState('error')
+ onError?.(e)
+ }
+ return
}
promise