UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

10 lines (8 loc) 741 B
/** * 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{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as n,useEffect as t,useMemo as o,useState as r,useRef as i}from"react";const c="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?n:t;function u(n){const[t]=e(),u=o((()=>n(t)),[t,n]),[a,d]=r((()=>u.initialValueFn())),l=i(a);return c((()=>{const{initialValueFn:e,subscribe:n}=u,t=e();return l.current!==t&&(l.current=t,d(t)),n((e=>{l.current=e,d(e)}))}),[u,n]),a}export{u as useLexicalSubscription};