Documentation
¶
Overview ¶
Package context provides a type-safe dependency injection mechanism for Vango applications.
Deprecated: Context injection is not part of the v1 Developer Guide. This package is retained for legacy/internal use only. Prefer explicit props, Setup/Closure composition, and SessionKey/SharedSignal for shared state.
It allows passing data through the component tree without manually passing props at every level (prop drilling). Features include:
- Generic, type-safe Context[T]
- Provider components for value injection
- Default values
- Nestable providers
Usage (legacy):
// Define context
var ThemeContext = context.Create("light")
// Provide value
func App() *vdom.VNode {
return ThemeContext.Provider("dark",
MainContent(),
)
}
// Consume value
func MainContent() *vdom.VNode {
theme := ThemeContext.Use()
return vdom.Div(vdom.Text("Current theme: " + theme))
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context
deprecated
type Context[T any] struct { // contains filtered or unexported fields }
Context provides a way to pass data through the component tree.
Deprecated: Context injection is not part of the v1 Developer Guide. This package is retained for legacy/internal use only. Prefer explicit props, Setup/Closure composition, and SessionKey/SharedSignal for shared state.
func (*Context[T]) Provider ¶
Provider creates a component that provides a value to its children. The provided value is scoped to descendants only (siblings won't see it). When the provider re-renders with a new value, all descendants that called Use() will be re-rendered (reactive).
func (*Context[T]) Use ¶
func (c *Context[T]) Use() T
Use retrieves the current context value. If no provider is found, returns the default value.
This is a reactive hook: it subscribes the calling component to the context value. When the Provider re-renders with a new value, this component will also re-render.