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)
| 68 | // Unlike UseVDomRef, this is not tied to DOM elements but holds arbitrary values. |
| 69 | // This hook must be called within a component context. |
| 70 | func 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 |
no test coverage detected