MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / UseRef

Function UseRef

tsunami/app/hooks.go:70–78  ·  view source on GitHub ↗

UseRef is the tsunami analog to React's useRef hook. It provides a mutable ref object that persists across re-renders. Unlike UseVDomRef, this is not tied to DOM elements but holds arbitrary values. This hook must be called within a component context.

(val T)

Source from the content-addressed store, hash-verified

68// Unlike UseVDomRef, this is not tied to DOM elements but holds arbitrary values.
69// This hook must be called within a component context.
70func UseRef[T any](val T) *vdom.VDomSimpleRef[T] {
71 rc := engine.GetGlobalRenderContext()
72 refVal := engine.UseRef(rc, &vdom.VDomSimpleRef[T]{Current: val})
73 typedRef, ok := refVal.(*vdom.VDomSimpleRef[T])
74 if !ok {
75 panic("UseRef hook value is not a ref (possible out of order or conditional hooks)")
76 }
77 return typedRef
78}
79
80// UseId returns the underlying component's unique identifier (UUID).
81// The ID persists across re-renders but is recreated when the component

Callers 1

app.goFile · 0.92

Calls 2

GetGlobalRenderContextFunction · 0.92
UseRefFunction · 0.92

Tested by

no test coverage detected