Skip to content

Render only a single component entirely on the client? | Monaco editor component #1194

Answered by gbj
Sett17 asked this question in Q&A
Discussion options

You must be logged in to vote
  1. I gave you a really dumb way to do this. Here's one that's much better:
    let editor_ref = create_node_ref::<html::Div>(cx);
    create_effect(cx, move |_| {
        use wasm_bindgen::JsCast;

        if let Some(div) = editor_ref.get() {
            let editor = monaco::api::CodeEditor::create(div.unchecked_ref(), Some(monaco::api::CodeEditorOptions::default()));
            on_cleanup(cx, move || drop(editor));
            log!("div: {:?}", div.outer_html());
        }
    });
    view! { cx,
        <div class="w-11/12 h-full border" node_ref=editor_ref></div>
    }
  1. The reason for the behavior, which I figured out after looking at the rust-monaco docs, is that they implement Drop

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Sett17
Comment options

@gbj
Comment options

Answer selected by Sett17
@Sett17
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants