Method UseFallback
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
UseFallback(Func<Exception, VNode>)
Registers a fallback factory inside Render() of an [Component(IsErrorBoundary = true)]
component. When this component catches a Render exception from a child, the registered factory
is invoked to produce the fallback VNode.
This API expresses, in functional Velvet, the Error Boundary pattern of returning a
fallback when a descendant render throws.
Must be called during Render since it is overwritten on every render.
public static void UseFallback(Func<Exception, VNode> factory)
Parameters
factoryFunc<Exception, VNode>Factory that receives the caught exception and returns the fallback VNode. Must not be null.
Remarks
When called from a non-EB component ([Component] with IsErrorBoundary=false), the
factory is still stored on the fiber, but RenderFallback is only reached on the Error
Boundary path, so it is effectively a no-op. Do not call this hook from non-EB components.
null or itself throws, the exception
bubbles to the next enclosing Error Boundary, ultimately reaching the root, which unmounts the tree
and reports it to OnUncaughtError when no boundary catches it.
Once the component has caught, each later render of it invokes the factory again with the error
it caught and renders what it returns in place of its children, until the component remounts —
give it a new key to render its children again — or is reset through
UseErrorBoundaryReset(object?[]?, Action<ErrorBoundaryResetDetails>?). On those renders a factory that returns
null or throws passes the error to the boundary above, as it does at the catch.
UseFallback(Func<Exception, ErrorInfo, VNode>)
Two-argument fallback factory variant that receives the caught exception and an
ErrorInfo with the throwing fiber's ComponentStack, describing where
the error was caught.
public static void UseFallback(Func<Exception, ErrorInfo, VNode> factory)
Parameters
factoryFunc<Exception, ErrorInfo, VNode>Factory that receives
(exception, info)and returns the fallback VNode. Must not be null.
Remarks
Same bubble-up semantics as the single-arg overload: returning null or throwing
re-propagates the original exception to the next enclosing Error Boundary.