kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
FocusPlugin: refactor the useEffect for sanity
rodzic
889c2658ba
commit
fd19fa9e5b
|
@ -11,10 +11,6 @@ export const FOCUS_EDITOR_COMMAND: LexicalCommand<void> = createCommand();
|
||||||
const FocusPlugin: React.FC<IFocusPlugin> = ({ autoFocus }) => {
|
const FocusPlugin: React.FC<IFocusPlugin> = ({ autoFocus }) => {
|
||||||
const [editor] = useLexicalComposerContext();
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
const focus = () => {
|
|
||||||
editor.dispatchCommand(FOCUS_EDITOR_COMMAND, undefined);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => editor.registerCommand(FOCUS_EDITOR_COMMAND, () => {
|
useEffect(() => editor.registerCommand(FOCUS_EDITOR_COMMAND, () => {
|
||||||
editor.focus(
|
editor.focus(
|
||||||
() => {
|
() => {
|
||||||
|
@ -29,8 +25,10 @@ const FocusPlugin: React.FC<IFocusPlugin> = ({ autoFocus }) => {
|
||||||
}, COMMAND_PRIORITY_NORMAL));
|
}, COMMAND_PRIORITY_NORMAL));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (autoFocus) focus();
|
if (autoFocus) {
|
||||||
}, []);
|
editor.dispatchCommand(FOCUS_EDITOR_COMMAND, undefined);
|
||||||
|
}
|
||||||
|
}, [autoFocus, editor]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
Ładowanie…
Reference in New Issue