@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
10 lines (8 loc) • 680 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.
*
*/
import{useLexicalComposerContext as r}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as t,useEffect as e,useMemo as n,useState as i,useRef as o}from"react";import{CAN_USE_DOM as c}from"lexical";const a=c?t:e;function l(t){const[e]=r(),c=n(()=>t(e),[e,t]),[l,u]=i(()=>c.initialValueFn()),m=o(l);return a(()=>{const{initialValueFn:r,subscribe:t}=c,e=r();return m.current!==e&&(m.current=e,u(e)),t(r=>{m.current=r,u(r)})},[c,t]),l}export{l as useLexicalSubscription};