-
Hi there, I'm facing an issue with the useEditorRef hook, where it doesn't seem to reference the intended editor by id. Despite specifying the id of a specific editor instance, it always returns the currently active editor. I'm trying to use it from a plugin component from inside an editor. Is this an issue, or am I misunderstanding its usage? Any suggestions or fixes would be greatly appreciated. Thanks! import { PlateElement, createPluginFactory } from "@udecode/plate-common";
import { useEditorRef } from "@udecode/plate-common";
const ELEMENT_SENTENCE = "sentence";
function SentenceElement({ className, children, ...props }) {
const outputEditor = useEditorRef("output-editor");
console.log("output editor: ", outputEditor.id);
// always logs "input-editor" which is the active one
return (
<PlateElement asChild className={`${className}`} {...props}>
<span>
{children}
</span>
</PlateElement>
);
}
export const createSentencePlugin = createPluginFactory({
key: ELEMENT_SENTENCE,
isElement: true,
component: SentenceElement,
}); |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Can you double check what |
Beta Was this translation helpful? Give feedback.
-
If it's still giving the wrong editor, can you add a breakpoint to this line in jotai-x and make sure that the scope is |
Beta Was this translation helpful? Give feedback.
-
If, on the other hand, |
Beta Was this translation helpful? Give feedback.
-
Hi Joe, Thanks for your answer! I tried using However, I've put together the simplest implementation of the issue in a CodeSandbox. Maybe someone can debug it better or has an idea on how to access another editor from inside a plugin component. |
Beta Was this translation helpful? Give feedback.
This works like React context: it needs to be above the component. That should work: