Table of Contents

Method Memo

Namespace
Velvet
Assembly
Velvet.Docs.dll

Memo<TProps>(Func<TProps, VNode>, TProps, Func<TProps, TProps, bool>, string?)

Memoizes a component with a custom areEqual comparator. Embeds a props-receiving function component (the same shape as Component<TProps>(Func<TProps, VNode>, TProps, string?)) but supplies an explicit areEqual predicate that decides whether a parent re-render bails this component.

public static ComponentNode Memo<TProps>(Func<TProps, VNode> body, TProps props, Func<TProps, TProps, bool> areEqual, string? key = null)

Parameters

body Func<TProps, VNode>

Delegate of a static method annotated with [Component] taking a single TProps parameter.

props TProps

The props value to pass to body.

areEqual Func<TProps, TProps, bool>

Predicate comparing previous and next props; returns true to bail the re-render. Must not be null (use the propless V.Component overload when no props comparison is needed).

key string

Key used to disambiguate siblings at the same position.

Returns

ComponentNode

The created ComponentNode carrying the custom comparator.

Type Parameters

TProps

Props type. Use sealed record (reference type) to avoid boxing.

Remarks

areEqual receives the previous and next props and returns true to bail (skip re-render). When the default shallow per-property identity comparison is sufficient, prefer plain V.Component(body, props) with [Component(Memoize = true)]; this overload is for the cases where shallow equality is too coarse or too fine (e.g. comparing only a subset of props, or deep-comparing one field).
Attributes cannot carry delegates, so the comparator is supplied here at the call site rather than on [Component].