Method Provider
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
Provider<T>(ComponentContext<T>, T, VNode?[]?, string?)
Provides a context value to the descendant subtree, visible to descendants that read the
same context via Hooks.UseContext.
public static ContextProviderNode<T> Provider<T>(ComponentContext<T> context, T value, VNode?[]? children = null, string? key = null)
Parameters
contextComponentContext<T>Context object whose value is being provided.
valueTValue visible to descendants via
Hooks.UseContext(context).childrenVNode[]Descendant VNodes that observe this provider.
keystringKey used to disambiguate siblings at the same position.
Returns
- ContextProviderNode<T>
The created ContextProviderNode<T>.
Type Parameters
TContext value type.
Remarks
A value change reaches consumers by comparing this provider against the one that held the same
position last render, and an unkeyed provider is identified by its own sibling index. That covers
the ordinary cases, including a conditional sibling rendered as null, which keeps its slot.
Give the provider an explicit key when the index itself can move — it follows a
variable number of siblings, or is appended after a mapped list — so it stays identified across
the shift. The key pins the provider's own place among its siblings, not the path above it: if an
unkeyed fragment or component enclosing it is what moves, key the moving ancestor too.