mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-08-06 13:38:49 +08:00
Allow passing of DependencyList to useEditor
in case the options depend on props of the consuming component, it would be nice to be able to pass a dependencylist to `useEditor`. Unless there's a better way to handle dependency updates
This commit is contained in:
parent
42c0ca85b3
commit
bdd6e2b87c
@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useState, useEffect, DependencyList } from 'react'
|
||||
import { EditorOptions } from '@tiptap/core'
|
||||
import { Editor } from './Editor'
|
||||
|
||||
@ -8,7 +8,7 @@ function useForceUpdate() {
|
||||
return () => setValue(value => value + 1)
|
||||
}
|
||||
|
||||
export const useEditor = (options: Partial<EditorOptions> = {}) => {
|
||||
export const useEditor = (options: Partial<EditorOptions> = {}, deps: DependencyList = []) => {
|
||||
const [editor, setEditor] = useState<Editor | null>(null)
|
||||
const forceUpdate = useForceUpdate()
|
||||
|
||||
@ -22,7 +22,7 @@ export const useEditor = (options: Partial<EditorOptions> = {}) => {
|
||||
return () => {
|
||||
instance.destroy()
|
||||
}
|
||||
}, [])
|
||||
}, deps)
|
||||
|
||||
return editor
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user