@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
37 lines (31 loc) • 1.15 kB
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 { AriaLiveRegionExtension } from '@lexical/a11y';
import { getExtensionDependencyFromEditor } from '@lexical/extension/getExtensionDependencyFromEditor';
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import { useCallback } from 'react';
/**
* 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.
*
*/
/**
* Returns a stable `announce` function backed by the editor's
* {@link AriaLiveRegionExtension} output. Requires
* `AriaLiveRegionExtension` in the editor's extension tree.
*/
function useLexicalAriaLiveRegion() {
const [editor] = useLexicalComposerContext();
return useCallback(message => {
const dep = getExtensionDependencyFromEditor(editor, AriaLiveRegionExtension);
dep.output.announce(message);
}, [editor]);
}
export { useLexicalAriaLiveRegion };