@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
10 lines (8 loc) • 722 B
JavaScript
/**
* 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.
*
*/
;var e=require("@lexical/react/LexicalComposerContext"),t=require("react");const n="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;exports.useLexicalSubscription=function(r){const[u]=e.useLexicalComposerContext(),i=t.useMemo((()=>r(u)),[u,r]),[o,c]=t.useState((()=>i.initialValueFn())),s=t.useRef(o);return n((()=>{const{initialValueFn:e,subscribe:t}=i,n=e();return s.current!==n&&(s.current=n,c(n)),t((e=>{s.current=e,c(e)}))}),[i,r]),o};