Method ErrorBoundary
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
ErrorBoundary(Func<Exception, VNode>, VNode?[], string?)
Helper that wraps children in an inline Error Boundary with the given fallback.
Catches exceptions thrown during render of the child tree (including rethrows from pending Suspense
resources via Hooks.Use) and renders the VNode produced by fallback instead.
Useful for reducing boilerplate where introducing a dedicated [Component(IsErrorBoundary = true)]
wrapper class would be overkill (e.g. a root boundary directly under Mount).
public static ComponentNode ErrorBoundary(Func<Exception, VNode> fallback, VNode?[] children, string? key = null)
Parameters
fallbackFunc<Exception, VNode>Factory that receives the caught exception and returns the fallback VNode.
childrenVNode[]Child nodes rendered in the normal (non-error) path.
keystringKey used to disambiguate siblings at the same position.
Returns
- ComponentNode
The created ComponentNode wrapping
childrenin an Error Boundary.
Remarks
When placing multiple V.ErrorBoundary instances at the same position, always supply
key to avoid identity collisions in the reconciler. The helper's lambda body
has the same MethodInfo on every call, so siblings cannot be distinguished without a key.
Each render of the parent hands the boundary the fallback and
children of that call.
Each invocation allocates a closure (DisplayClass + delegate). The helper is intended for
root boundaries directly under Mount; calling it repeatedly inside a render function will
allocate on every render.
ErrorBoundary(Func<Exception, ErrorBoundaryReset, VNode>, VNode?[], object?[]?, Action<ErrorBoundaryResetDetails>?, string?)
Variant of ErrorBoundary(Func<Exception, VNode>, VNode?[], string?) whose fallback receives the
boundary's reset — react-error-boundary's <ErrorBoundary fallbackRender resetKeys onReset>,
whose fallbackRender receives error and resetErrorBoundary.
public static ComponentNode ErrorBoundary(Func<Exception, ErrorBoundaryReset, VNode> fallbackRender, VNode?[] children, object?[]? resetKeys = null, Action<ErrorBoundaryResetDetails>? onReset = null, string? key = null)
Parameters
fallbackRenderFunc<Exception, ErrorBoundaryReset, VNode>Receives the caught exception and the boundary's reset, and returns the fallback VNode.
childrenVNode[]Child nodes rendered in the normal (non-error) path.
resetKeysobject[]Values whose change resets the boundary.
onResetAction<ErrorBoundaryResetDetails>Called before each reset, with what reset the boundary.
keystringKey used to disambiguate siblings at the same position.
Returns
- ComponentNode
The created ComponentNode wrapping
childrenin an Error Boundary.
Remarks
resetKeys and onReset behave as they do on
UseErrorBoundaryReset(object?[]?, Action<ErrorBoundaryResetDetails>?), which states when the boundary resets.