question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set the element after instantiation

See original GitHub issue

Is your feature request related to a problem? Please describe. Instantiation

Describe the solution you’d like I’d like to be able to create the editor without an element, and use a method to set the element elsewhere in my app.

This way we can create the editor() without having to know if the DOM is ready, nor which element will be responsible for rendering. This will help me decouple the various UI elements for my application, ie:

// Pseudocode
const tiptap = new Editor({ ... });
<Container>
    <Toolbar>
    <Sidebar>
    <Editor-Document>
    <Breadcrumbs>
</Container>

^ in this example the <Editor-Document> may get access to tiptap and call tiptap.setElement(...) once ready. Other components may also get access to tiptap to listen to events etc.

Describe alternatives you’ve considered

Tried this without success

// Create without an element:
editor = new Editor({ ... });

// Set the element later
editor.setOptions({ element: document.getElementById('the-editor'), });

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hanspagelcommented, Jan 28, 2021

Thanks, I updated the documentation!

0reactions
oodavidcommented, Jan 27, 2021

Since I can’t fork the repo, this is my docs proposal:

https://github.com/ueberdosis/tiptap-next/blob/main/docs/src/docPages/api/editor.md


Init before mounting

You can initiate your editor before mounting. This is useful when your DOM is not yet available, or you want to decouple the editor from the DOM.

import { Editor } from '@tiptap/core'
import { defaultExtensions } from '@tiptap/starter-kit'
const element = document.createElement('div')
new Editor({
  element: element,
  extensions: defaultExtensions(),
})

You can then mount the element at a later date.

yourContainerElement.append(element)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Set the element after instantiation · Issue #1161 - GitHub
I can wait for the DOM, but it means I have a round trip - I want the editor to be created without...
Read more >
Can one add React Keys after instantiation? - Stack Overflow
I'm making a collection of React Elements and displaying them; what follows is a trivial example to frame the problem of ...
Read more >
Set - JavaScript - MDN Web Docs - Mozilla
The Set object lets you store unique values of any type, whether primitive values or object references.
Read more >
Problem with instantiate UI prefabs - Unity Forum
When I instantiate prefab with RectTransform on it in most cases it works wrong. Usually ancoredPosition and deltaSize resets and I have to ......
Read more >
Different ways to instantiate an object in C++ with Examples
example *obj2 = new example(): This is the way of instantiating an object that has dynamic storage duration. This object will not be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found