UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

54 lines (50 loc) 1.51 kB
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import { getExtensionDependencyFromEditor } from '@lexical/extension'; import { ReactExtension } from '@lexical/react/ReactExtension'; import { useEffect } from 'react'; import { jsx } from 'react/jsx-runtime'; /** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ /** * The equivalent of LexicalComposer for an editor that was already built for * extensions, typically used with nested editors. * * Make sure that your initialEditor argument is stable (e.g. using module scope or useMemo) so * that you are not re-creating the editor on every render! The editor should be built with * ReactProviderExtension and ReactExtension dependencies. */ function LexicalExtensionEditorComposer({ initialEditor: editor, children }) { useEffect(() => { // Strict mode workaround let didMount = false; queueMicrotask(() => { didMount = true; }); return () => { if (didMount) { editor.dispose(); } }; }, [editor]); const { Component } = getExtensionDependencyFromEditor(editor, ReactExtension).output; return /*#__PURE__*/jsx(Component, { children: children }); } export { LexicalExtensionEditorComposer };