How to keep state between Editor and Extensions? #6179
Replies: 1 comment 1 reply
-
Let me understand your requirement: You want to dynamically modify the placeholder, similar to Unfortunately, Tiptap does not support this operation. All required extensions are specified when the editor is created and cannot be modified during the editor's lifecycle. This means that when the placeholder changes, you need to recreate the entire editor. Tiptap is built on top of ProseMirror, and the So you can achieve dynamic placeholder support in the following way: const MyPlaceholderReactComponent = (props: { children?: string }) => {
const pluginKey = useMemo(() => {
// your pluginKey here
}, []);
const plugin = useMemo(() => {
// your plugin here
}, []);
useEffect(() => {
editor.registerPlugin(plugin);
return () => {
editor.unregisterPlugin(pluginKey);
};
}, [editor, plugin]);
return null;
}; Use this component like this: <MyPlaceholderReactComponent>
{placeholder}
</MyPlaceholderReactComponent> |
Beta Was this translation helpful? Give feedback.
-
Hello there 👋
I have the following component in my React app, and I'm trying to keep its state synced with my extension and its props. My current approach uses
useEffect
todispatch
the latest prop changes with the extension but I feel like this is not the right approach, or is it?I thought when the Tiptap component was rerendered due to the props changes, the extension
Placeholder.configure
would be tacking the new properties, but it is not.Beta Was this translation helpful? Give feedback.
All reactions