Counter
In this chapter, we introduce event handlers. Take a look at this demo, with plus and minus buttons that increment and decrement a counter. You may remember it from the pupy.dev homepage.
In this example, we bind two events to event handlers. Follow along with the annotations in the code below for a more detailed explanation:
- The 
on_clickparameter is passed to thebuttontag, which binds theon_decrement_clickmethod to the button's click event. - The 
on_clickparameter is passed to thebuttontag, which binds theon_increment_clickmethod to the button's click event. - The 
on_decrement_clickmethod decrements thecurrent_valuekey in the page's state. - The 
on_increment_clickmethod increments thecurrent_valuekey in the page's state. 
Tip
The event parameter sent to event handlers is the same as it is in JavaScript. You can call event.preventDefault() or event.stopPropagation() as needed.
As before, because we are modifying the state directly, the page will re-render automatically. This is the power of PuePy's reactivity system.