@@ -287,26 +287,7 @@ func P(propName string, propVal any) any {
287287 return map [string ]any {propName : propVal }
288288}
289289
290- func UseState [T any ](ctx context.Context , initialVal T ) (T , func (T )) {
291- vc := GetRenderContext (ctx )
292- hookVal := vc .GetOrderedHook ()
293- if ! hookVal .Init {
294- hookVal .Init = true
295- hookVal .Val = initialVal
296- }
297- var rtnVal T
298- rtnVal , ok := hookVal .Val .(T )
299- if ! ok {
300- panic ("UseState hook value is not a state (possible out of order or conditional hooks)" )
301- }
302- setVal := func (newVal T ) {
303- hookVal .Val = newVal
304- vc .AddRenderWork (vc .GetCompWaveId ())
305- }
306- return rtnVal , setVal
307- }
308-
309- func UseStateWithFn [T any ](ctx context.Context , initialVal T ) (T , func (T ), func (func (T ) T )) {
290+ func UseState [T any ](ctx context.Context , initialVal T ) (T , func (T ), func (func (T ) T )) {
310291 vc := GetRenderContext (ctx )
311292 hookVal := vc .GetOrderedHook ()
312293 if ! hookVal .Init {
@@ -332,7 +313,7 @@ func UseStateWithFn[T any](ctx context.Context, initialVal T) (T, func(T), func(
332313 return rtnVal , setVal , setFuncVal
333314}
334315
335- func UseAtom [T any ](ctx context.Context , atomName string ) (T , func (T )) {
316+ func UseSharedAtom [T any ](ctx context.Context , atomName string ) (T , func (T ), func ( func ( T ) T )) {
336317 vc := GetRenderContext (ctx )
337318 hookVal := vc .GetOrderedHook ()
338319 if ! hookVal .Init {
@@ -355,7 +336,13 @@ func UseAtom[T any](ctx context.Context, atomName string) (T, func(T)) {
355336 vc .AddRenderWork (waveId )
356337 }
357338 }
358- return atomVal , setVal
339+ setFuncVal := func (updateFunc func (T ) T ) {
340+ atom .Val = updateFunc (atom .Val .(T ))
341+ for waveId := range atom .UsedBy {
342+ vc .AddRenderWork (waveId )
343+ }
344+ }
345+ return atomVal , setVal , setFuncVal
359346}
360347
361348func UseVDomRef (ctx context.Context ) * VDomRef {
0 commit comments