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

Function getHookFromCtx

pkg/vdom/vdom.go:301–315  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

299}
300
301func getHookFromCtx(ctx context.Context) (*VDomContextVal, *Hook) {
302 vc := getRenderContext(ctx)
303 if vc == nil {
304 panic("UseState must be called within a component (no context)")
305 }
306 if vc.Comp == nil {
307 panic("UseState must be called within a component (vc.Comp is nil)")
308 }
309 for len(vc.Comp.Hooks) <= vc.HookIdx {
310 vc.Comp.Hooks = append(vc.Comp.Hooks, &Hook{Idx: len(vc.Comp.Hooks)})
311 }
312 hookVal := vc.Comp.Hooks[vc.HookIdx]
313 vc.HookIdx++
314 return vc, hookVal
315}
316
317func UseState[T any](ctx context.Context, initialVal T) (T, func(T)) {
318 vc, hookVal := getHookFromCtx(ctx)

Callers 6

UseStateFunction · 0.85
UseStateWithFnFunction · 0.85
UseAtomFunction · 0.85
UseVDomRefFunction · 0.85
UseRefFunction · 0.85
UseEffectFunction · 0.85

Calls 1

getRenderContextFunction · 0.85

Tested by

no test coverage detected