mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-23 19:19:03 +08:00
chore: memoize the editor context value
This commit is contained in:
parent
6b2df67219
commit
e2787e4736
@ -1,6 +1,7 @@
|
||||
import { Editor } from '@tiptap/core'
|
||||
import React, {
|
||||
createContext, HTMLAttributes, ReactNode, useContext,
|
||||
useMemo,
|
||||
} from 'react'
|
||||
|
||||
import { EditorContent } from './EditorContent.js'
|
||||
@ -37,13 +38,14 @@ export function EditorProvider({
|
||||
children, slotAfter, slotBefore, editorContainerProps = {}, ...editorOptions
|
||||
}: EditorProviderProps) {
|
||||
const editor = useEditor(editorOptions)
|
||||
const editorContextValue = useMemo(() => ({ editor }), [editor])
|
||||
|
||||
if (!editor) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<EditorContext.Provider value={{ editor }}>
|
||||
<EditorContext.Provider value={editorContextValue}>
|
||||
{slotBefore}
|
||||
<EditorConsumer>
|
||||
{({ editor: currentEditor }) => (
|
||||
|
Loading…
Reference in New Issue
Block a user