Table of Contents

Class ComponentAttribute

Namespace
Velvet
Assembly
Velvet.Docs.dll

Registers a functional component (static VNode XxxComp()) as a Velvet component.

[AttributeUsage(AttributeTargets.Method, Inherited = false)]
public sealed class ComponentAttribute : Attribute
Inheritance
object
Attribute
ComponentAttribute

Remarks

A static method annotated with [Component] must:

  • Return VNode and take no arguments (Render is parameterless)
  • Access external state only through Hooks (UseStore / UseContext / UseState, etc.)
  • Follow the Rules of Hooks — call hooks unconditionally, in a stable order, only inside Render. These are enforced at runtime (a violation throws System.InvalidOperationException), not by a compile-time analyzer
  • Be referenced from a parent VNode tree as V.Component(MyComp.Render)

Two independent memoization axes — Memoize (props-bail) and Compiler (build-time auto-memo); see each member.

Properties

Compiler

Whether the build-time compiler transform — inner auto-memoization — is woven into this component. Default is true: the transform caches the component's VNode construction keyed on the values flowing out of its hook calls (and its props), rebuilding only when one of those inputs changes by reference/value identity. Every component is auto-memoized with no opt-in, so this is on by default for all components.

Set to false to opt this component out of the transform, so its body then runs in full on every render. This is an escape hatch for the rare component whose render must not be cached; it is orthogonal to Memoize, which governs the props-bail axis at the reconcile boundary.

DisplayName

Optional debug name used in hook-rule violation messages and other diagnostics in place of the default "DeclaringType.MethodName" form. When null or empty, the default name is used.

IsErrorBoundary

Whether this component behaves as an Error Boundary. Default is false.

Memoize

Opt-in props-bail: skip a parent-driven re-render when this component's props are shallow-equal to the previous render (each property compared by reference/value identity). Default is false.

This is a true opt-in gate: only a component with Memoize = true (or one created via V.Memo with a custom comparator) bails on shallow-equal props. A component without it re-renders whenever its parent re-renders; only an opted-in component skips a re-render on equal props.