How to best read editor value inside of a callback? #2990
-
Previously when Plate used zustand, you could read the value of the editor in a callback like so: const plateStore = usePlateStore();
const logCurrentValue = useCallback(
() => {
console.log(plateStore.get.value());
},
[plateStore],
); This would result in a pretty stable callback reference that can lazily read the current editor value and the component will minimally re-render. However, after the change to jotai, this will throw an error since While you can do something like this: const value = usePlateStore().get.value();
const logCurrentValue = useCallback(
() => {
console.log(value);
},
[value],
); The component will now re-render anytime value changes, which is undesirable. How should one best lazily read the current editor value inside of a callback? It see the pattern to do this in jotai is to use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
const editor = useEditorRef()
const value = editor.children |
Beta Was this translation helpful? Give feedback.
editor.children
refers to the same value: