context

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 2 Imported by: 0

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 Create

func Create[T any](defaultValue T) *Context[T]

Create creates a new Context with a default value.

func (*Context[T]) Provider

func (c *Context[T]) Provider(value T, children ...any) *vdom.VNode

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL