Skip to content

Instantly share code, notes, and snippets.

@hanford
Created July 13, 2022 17:49
Show Gist options
  • Save hanford/e7e7ee1bc3883c2e1204c3eea66e3dac to your computer and use it in GitHub Desktop.
Save hanford/e7e7ee1bc3883c2e1204c3eea66e3dac to your computer and use it in GitHub Desktop.
import { useEffect } from 'react';
import { BLUR_COMMAND, COMMAND_PRIORITY_NORMAL } from 'lexical';
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
export default function OnBlurPlugin({ command }: { command: () => void }) {
const [editor] = useLexicalComposerContext();
useEffect(() => {
return editor.registerCommand(
BLUR_COMMAND,
() => {
command();
return true;
},
COMMAND_PRIORITY_NORMAL,
);
}, [editor, command]);
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment