@@ -23,17 +23,17 @@ import reflex as rx
2323class MyState (rx .State ):
2424 count: int = 0
2525
26- @rx.event
27- def increment (self , amount : int ):
28- self .count += amount
26+ @rx.event
27+ def increment (state : MyState , amount : int ):
28+ state .count += amount
2929
3030def decentralized_event_example ():
3131 return rx.vstack(
3232 rx.heading(f " Count: { MyState.count} " ),
3333 rx.hstack(
34- rx.button(" Increment by 1" , on_click = lambda : MyState. increment(1 )),
35- rx.button(" Increment by 5" , on_click = lambda : MyState. increment(5 )),
36- rx.button(" Increment by 10" , on_click = lambda : MyState. increment(10 )),
34+ rx.button(" Increment by 1" , on_click = increment(1 )),
35+ rx.button(" Increment by 5" , on_click = increment(5 )),
36+ rx.button(" Increment by 10" , on_click = increment(10 )),
3737 ),
3838 spacing = " 4" ,
3939 align = " center" ,
@@ -53,11 +53,11 @@ Here's a comparison between traditional event handlers defined within state clas
5353# Traditional event handler within a state class
5454class TraditionalState (rx .State ):
5555 count: int = 0
56-
56+
5757 @rx.event
5858 def increment (self , amount : int = 1 ):
5959 self .count += amount
60-
60+
6161# Usage in components
6262rx.button(" Increment" , on_click = TraditionalState.increment(5 ))
6363
0 commit comments