reactpy icon indicating copy to clipboard operation
reactpy copied to clipboard

Support for string events (to execute raw javascript)

Open Archmonger opened this issue 10 months ago • 0 comments

Current Situation

There's currently no existing capabilities for running a JS script from within an event tag.

Additionally, string based events serialized from html_to_vdom currently do not execute at all.

Proposed Actions

Allow events to be declared as string type. If the event is a string, pass it directly into React's prop dictionary, which will allow it to execute as traditional javascript.

@component
def my_component():
    return html.button(
        { "onClick": "$('.sidebar').toggle()" },
        "This is a button!",
    )

In this scenario, providing a str within onClick would execute the event string the client side.

Originally posted by @Archmonger in https://github.com/reactive-python/reactpy/discussions/783

Archmonger avatar Jan 28 '25 04:01 Archmonger