(ctx context.Context, initialVal T)
| 333 | } |
| 334 | |
| 335 | func 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 | |
| 360 | func UseAtom[T any](ctx context.Context, atomName string) (T, func(T)) { |
| 361 | vc, hookVal := getHookFromCtx(ctx) |
nothing calls this directly
no test coverage detected