tiptap/packages/vue-3/src/useEditor.ts

18 lines
392 B
TypeScript

import { onMounted, onBeforeUnmount, shallowRef } from 'vue'
import { EditorOptions } from '@tiptap/core'
import { Editor } from './Editor'
export const useEditor = (options: Partial<EditorOptions> = {}) => {
const editor = shallowRef<Editor>()
onMounted(() => {
editor.value = new Editor(options)
})
onBeforeUnmount(() => {
editor.value?.destroy()
})
return editor
}