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

Function UseStateWithFn

pkg/vdom/vdom.go:335–358  ·  view source on GitHub ↗
(ctx context.Context, initialVal T)

Source from the content-addressed store, hash-verified

333}
334
335func UseStateWithFn[T any](ctx context.Context, initialVal T) (T, func(T), func(func(T) T)) {
336 vc, hookVal := getHookFromCtx(ctx)
337 if !hookVal.Init {
338 hookVal.Init = true
339 hookVal.Val = initialVal
340 }
341 var rtnVal T
342 rtnVal, ok := hookVal.Val.(T)
343 if !ok {
344 panic("UseState hook value is not a state (possible out of order or conditional hooks)")
345 }
346
347 setVal := func(newVal T) {
348 hookVal.Val = newVal
349 vc.Root.AddRenderWork(vc.Comp.WaveId)
350 }
351
352 setFuncVal := func(updateFunc func(T) T) {
353 hookVal.Val = updateFunc(hookVal.Val.(T))
354 vc.Root.AddRenderWork(vc.Comp.WaveId)
355 }
356
357 return rtnVal, setVal, setFuncVal
358}
359
360func UseAtom[T any](ctx context.Context, atomName string) (T, func(T)) {
361 vc, hookVal := getHookFromCtx(ctx)

Callers

nothing calls this directly

Calls 2

getHookFromCtxFunction · 0.85
AddRenderWorkMethod · 0.80

Tested by

no test coverage detected