useContext<T> function
Reads the current ambient value for context from the surrounding Zone.
If an ancestor ContextProviderNode provided a value for context, that
value is returned. If no provider is found in the current zone hierarchy,
returns context.defaultValue.
Reactive Note
Calling useContext is not reactive by itself. If you need UI to update when
context data changes, store a Signal<T> in the context and read signal.value
inside a Live or Show boundary.
BloomNode userBadge() {
final user = useContext(authContext);
return Span(
text: user != null ? 'Logged in as ${user.name}' : 'Anonymous',
);
}
Implementation
T useContext<T>(BloomContext<T> context) {
final value = Zone.current[context.zoneKey];
if (value != null && value is T) return value;
return context.defaultValue;
}