Clearing the editor with replaceWith

I wanted to clear the editor with an external action. Passing null to tr.replaceWith seems to work, but it does not feel like it is the right approach. I tried passing state.schema.text('') too, but I get the Uncaught RangeError: Empty text nodes are not allowed error.

    const { state } = view;
    const tr =;
    tr.replaceWith(0, state.doc.content.size, null);
    const newState = state.apply(tr);

What would be the appropriate action?

What would be the best way to dynamically add html content instead of using tr.insertText()

That replaceWith call should work (though delete would be simpler).

is it ok to pass null?

i also wanted to dynamically insert into the editor content that has html tags (html content). what better method is available for doing that. the insertText method shows the tags as strings.

That sounds like a question for the docs. And the docs answer no. (But you can pass an empty fragment if you really want to use replaceWith to delete something.)