Created
July 13, 2022 17:49
-
-
Save hanford/e7e7ee1bc3883c2e1204c3eea66e3dac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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