MCPcopy
hub / github.com/preactjs/preact / useErrorBoundary

Function useErrorBoundary

hooks/src/index.js:400–417  ·  view source on GitHub ↗
(cb)

Source from the content-addressed store, hash-verified

398 * @returns {[unknown, () => void]}
399 */
400export 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} */
420export function useId() {

Callers 3

AppFunction · 0.90
AppFunction · 0.90
TodoItemFunction · 0.90

Calls 2

getHookStateFunction · 0.85
useStateFunction · 0.85

Tested by 3

AppFunction · 0.72
AppFunction · 0.72
TodoItemFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…