reactpy icon indicating copy to clipboard operation
reactpy copied to clipboard

`use_script` hook

Open Archmonger opened this issue 2 years ago • 0 comments

Current Situation

Currently, there is no method to transmit the results of a JavaScript function to the backend.

Proposed Actions

Create a use_script hook that operates similarly to html.script, but can return a result.

For example,

@component
def example():
    script = use_script("getComputedStyle(document.querySelector('#element'))")
    return f"CSS Style Attributes: {script.data}"

Since this hook operates asynchronously, the interface should pretty much match our Django use_query hook.

See this comment for traceability.

As a note, it's going to be very important for us to pre-populated the this element with the current DOM node.

Archmonger avatar Jan 29 '23 03:01 Archmonger