How to add Event Listener dynamically? #2423
Answered
by
gbj
dvorakchen
asked this question in
Q&A
-
I was try to add a event listener to body, and I found a way: create_effect(|_| {
document().body().unwrap().add_event_listener_with_callback(
"click",
&Function::new_no_args(
"
JS code here
",
),
)
}); but as you see I can only write JS code in callback function, that mean I cannot use signal. is anybody has better idea? |
Beta Was this translation helpful? Give feedback.
Answered by
gbj
Mar 13, 2024
Replies: 1 comment
-
To just add an event listener on the window, use one of these helpers If you need something more specific than that, you should drop into using |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dvorakchen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To just add an event listener on the window, use one of these helpers
If you need something more specific than that, you should drop into using
wasm-bindgen
'sClosure
type to wrap Rust code as a JS function, rather than creating a function from a JS string. See their docs here