Can I use externally created HtmlElement in leptos? #2009
Answered
by
gbj
liukaizheng
asked this question in
Q&A
-
use winit::event_loop;
use winit::platform::web::WindowExtWebSys;
let event_loop = event_loop::EventLoop::new()?;
let window = winit::window::Window::new(&event_loop)?;
let mut canvas = window.canvas().expect("window should have a canvas by now");
...
view! {
<canvas node_ref = canvas />
} Can I use this |
Beta Was this translation helpful? Give feedback.
Answered by
gbj
Nov 10, 2023
Replies: 1 comment 4 replies
-
Sure. Probably the easiest way to do this is on a use leptos::*;
#[component]
pub fn App() -> impl IntoView {
// here, I just create a canvas
// but this can be the canvas you get from winit
let some_canvas = document().create_element("canvas").unwrap();
let parent = NodeRef::<html::Div>::new();
create_effect(move |_| {
if let Some(parent) = parent.get() {
parent.append_child(&some_canvas);
}
});
view! {
<div node_ref=parent/>
}
} |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
liukaizheng
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sure. Probably the easiest way to do this is on a
NodeRef
containing whatever the parent element should be: