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
bodyFunc<TProps, VNode>Delegate of a static method annotated with
[Component]taking a singleTPropsparameter.propsTPropsThe props value to pass to
body.areEqualFunc<TProps, TProps, bool>Predicate comparing previous and next props; returns
trueto bail the re-render. Must not be null (use the proplessV.Componentoverload when no props comparison is needed).keystringKey used to disambiguate siblings at the same position.
Returns
- ComponentNode
The created ComponentNode carrying the custom comparator.
Type Parameters
TPropsProps 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].