SupButton
The SupButton object represents an interactive button in Sup that can trigger callbacks when clicked. It is created using sup.button(), and should be returned from the main() function.
SupButton: { "label": "Click me!", "userEventToken": "abc123"}Constructor
sup.button(label, clickCallbackFn, value?)
const button = sup.button("Click me!", () => { console.log("Button clicked!");});Parameters:
label: The text to display on the buttonclickCallbackFn: A function to call when the button is clicked. Must be defined at the top level of your patch.value: Optional value to pass to the callback function
The click callback function receives an argument of type:
{ "user": SupUser, // The user who clicked the button "value": any // The value passed when creating the button}Properties
label
type: string
The text displayed on the button.
userEventToken
type: string
A unique token used internally to track button clicks.
Notes
- The callback function must be defined at the top level of your patch (not inside other functions)
- The callback receives a single argument containing both the user who clicked and the value passed when creating the button
- For more examples of interactive elements, see the Adding Interactivity guide