Skip to content

Commit

Permalink
removed the second useEffect and used mergeRegister
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmuhtasimfuadfahim committed Oct 13, 2024
1 parent fc30d8d commit d6fa44c
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {ElementNode, RangeSelection} from 'lexical';

import {$getListDepth, $isListItemNode, $isListNode} from '@lexical/list';
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
import {mergeRegister} from '@lexical/utils';
import {
$getSelection,
$isElementNode,
Expand Down Expand Up @@ -76,19 +77,19 @@ export default function ListMaxIndentLevelPlugin({
const [editor] = useLexicalComposerContext();

useEffect(() => {
return editor.registerCommand(
INDENT_CONTENT_COMMAND,
() => $shouldPreventIndent(maxDepth),
COMMAND_PRIORITY_CRITICAL,
return mergeRegister(
editor.registerCommand(
INDENT_CONTENT_COMMAND,
() => $shouldPreventIndent(maxDepth),
COMMAND_PRIORITY_CRITICAL,
),
editor.registerCommand(
PASTE_COMMAND,
() => $shouldPreventIndent(maxDepth),
COMMAND_PRIORITY_CRITICAL,
),
);
}, [editor, maxDepth]);

useEffect(() => {
return editor.registerCommand(
PASTE_COMMAND,
() => $shouldPreventIndent(maxDepth),
COMMAND_PRIORITY_CRITICAL,
);
}, [editor, maxDepth]);
return null;
}

0 comments on commit d6fa44c

Please sign in to comment.