Files
tiptap/packages/vue-3/src/useEditor.ts
Philipp Kühn b5b9363b49 fix vue-3 build
2021-11-05 13:45:16 +01:00

24 lines
520 B
TypeScript

import {
onMounted,
onBeforeUnmount,
shallowRef,
Ref,
} from 'vue'
import { EditorOptions } from '@tiptap/core'
import { Editor } from './Editor'
// We set a custom return type. Otherwise TypeScript will throw TS4023. Not sure why.
export const useEditor = (options: Partial<EditorOptions> = {}): Ref<Editor> => {
const editor = shallowRef<Editor>() as Ref<Editor>
onMounted(() => {
editor.value = new Editor(options)
})
onBeforeUnmount(() => {
editor.value?.destroy()
})
return editor
}