| 398 | * @returns {[unknown, () => void]} |
| 399 | */ |
| 400 | export function useErrorBoundary(cb) { |
| 401 | /** @type {import('./internal').ErrorBoundaryHookState} */ |
| 402 | const state = getHookState(currentIndex++, 10); |
| 403 | const errState = useState(); |
| 404 | state._value = cb; |
| 405 | if (!currentComponent.componentDidCatch) { |
| 406 | currentComponent.componentDidCatch = (err, errorInfo) => { |
| 407 | if (state._value) state._value(err, errorInfo); |
| 408 | errState[1](err); |
| 409 | }; |
| 410 | } |
| 411 | return [ |
| 412 | errState[0], |
| 413 | () => { |
| 414 | errState[1](undefined); |
| 415 | } |
| 416 | ]; |
| 417 | } |
| 418 | |
| 419 | /** @type {() => string} */ |
| 420 | export function useId() { |