diff --git a/packages/react/src/useEditor.ts b/packages/react/src/useEditor.ts index e80ca4a49a..0317c54aa7 100644 --- a/packages/react/src/useEditor.ts +++ b/packages/react/src/useEditor.ts @@ -8,8 +8,8 @@ import { import { Editor } from './Editor.js' -export const useEditor = (options: Partial = {}, deps: DependencyList = []) => { - const editorRef = useRef(null) +const useEditorBase = (options: Partial = {}, deps: DependencyList = [], availableOnFirstRender = false) => { + const editorRef = useRef(availableOnFirstRender ? new Editor(options) : null) const [, forceUpdate] = useState({}) const { @@ -124,3 +124,17 @@ export const useEditor = (options: Partial = {}, deps: Dependency return editorRef.current } + +export const useEditor = (options: Partial = {}, deps: DependencyList = []): Editor | null => { + const editor = useEditorBase(options, deps) + + return editor +} + +// In case you want to render the editor immediately, you can use this hook. +// Caution: Does not work with SSR. +export const useEditorForImmediateRender = (options: Partial = {}, deps: DependencyList = []): Editor => { + const editor = useEditorBase(options, deps, true) as Editor + + return editor +}