Skip to content

Commit

Permalink
Merge pull request #4084 from regmsif/fix/use-editor-plugin-rerender
Browse files Browse the repository at this point in the history
fix: return value of useEditorPlugin changes when rerender
  • Loading branch information
zbeyens authored Feb 18, 2025
2 parents 6b838e0 + 6b8e2f8 commit c36ff01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-keys-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-core': patch
---

fix: return value of useEditorPlugin changes when rerender
14 changes: 10 additions & 4 deletions packages/core/src/react/stores/plate/useEditorPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import type { AnyPluginConfig, WithRequiredKey } from '../../../lib';
import type { PlateEditor } from '../../editor';

Expand All @@ -21,8 +23,12 @@ export function useEditorPlugin<
} {
const editor = useEditorRef(id);

return {
...getEditorPlugin(editor, p),
store: editor.store,
} as any;
return React.useMemo(
() =>
({
...getEditorPlugin(editor, p),
store: editor.store,
}) as any,
[editor, p]
);
}

0 comments on commit c36ff01

Please sign in to comment.