UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

56 lines (51 loc) 1.57 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. * */ 'use strict'; var extension = require('@lexical/extension'); var ReactExtension = require('@lexical/react/ReactExtension'); var react = require('react'); var jsxRuntime = require('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 }) { react.useEffect(() => { // Strict mode workaround let didMount = false; queueMicrotask(() => { didMount = true; }); return () => { if (didMount) { editor.dispose(); } }; }, [editor]); const { Component } = extension.getExtensionDependencyFromEditor(editor, ReactExtension.ReactExtension).output; return /*#__PURE__*/jsxRuntime.jsx(Component, { children: children }); } exports.LexicalExtensionEditorComposer = LexicalExtensionEditorComposer;