Skip to content

Commit

Permalink
Fix endless renders with editorRef callback (#5701)
Browse files Browse the repository at this point in the history
  • Loading branch information
2wheeh authored Mar 11, 2024
1 parent 830b7e1 commit 8d37645
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/lexical-react/src/LexicalEditorRefPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ export function EditorRefPlugin({
| MutableRefObject<LexicalEditor | null | undefined>;
}): null {
const [editor] = useLexicalComposerContext();
if (typeof editorRef === 'function') {
editorRef(editor);
} else if (typeof editorRef === 'object') {
editorRef.current = editor;
}

React.useEffect(() => {
if (typeof editorRef === 'function') {
editorRef(editor);
} else if (typeof editorRef === 'object') {
editorRef.current = editor;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [editor]);

return null;
}

0 comments on commit 8d37645

Please sign in to comment.