@terrible-lexical/react
Version:
This package provides Lexical components and hooks for React applications.
26 lines (21 loc) • 722 B
text/typescript
/**
* 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 type {LexicalSubscription} from './useLexicalSubscription';
import type {LexicalEditor} from 'terrible-lexical';
import useLexicalSubscription from './useLexicalSubscription';
function subscription(editor: LexicalEditor): LexicalSubscription<boolean> {
return {
initialValueFn: () => editor.isEditable(),
subscribe: (callback) => {
return editor.registerEditableListener(callback);
},
};
}
export default function useLexicalEditable(): boolean {
return useLexicalSubscription(subscription);
}