| 315 | } |
| 316 | |
| 317 | func UseState[T any](ctx context.Context, initialVal T) (T, func(T)) { |
| 318 | vc, hookVal := getHookFromCtx(ctx) |
| 319 | if !hookVal.Init { |
| 320 | hookVal.Init = true |
| 321 | hookVal.Val = initialVal |
| 322 | } |
| 323 | var rtnVal T |
| 324 | rtnVal, ok := hookVal.Val.(T) |
| 325 | if !ok { |
| 326 | panic("UseState hook value is not a state (possible out of order or conditional hooks)") |
| 327 | } |
| 328 | setVal := func(newVal T) { |
| 329 | hookVal.Val = newVal |
| 330 | vc.Root.AddRenderWork(vc.Comp.WaveId) |
| 331 | } |
| 332 | return rtnVal, setVal |
| 333 | } |
| 334 | |
| 335 | func UseStateWithFn[T any](ctx context.Context, initialVal T) (T, func(T), func(func(T) T)) { |
| 336 | vc, hookVal := getHookFromCtx(ctx) |