Counting button

A button that counts how many times it's been clicked.

Demo

Code

This example uses the Lux frontend framework. In Lux, state lives in the DOM, and the useState method lets you maintain state in the parent node.

render(lux: Lux): Unit {
    lux.div {
        lux.useState(0): count, setCount => 
        lux.button {
            lux.text("Clicked " + count + " times")
            lux.onClick {event =>
                event.preventDefault()
                setCount(count + 1)
            }
        }
    }
}