Skip to content
Discussion options

You must be logged in to vote

Would something like this work for your use case? Fork of your code sandbox

const ResetEditorOnValueChange = ({ value }: { value: MyValue }) => {
  const resetPlateEditor = useResetPlateEditor();
  const isFirst = useRef(true);

  useEffect(() => {
    if (isFirst.current) {
      isFirst.current = false;
      return;
    }

    resetPlateEditor();
  }, [value, resetPlateEditor]);

  return null;
};

The isFirst is to prevent an infinite re-render loop.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@fbolcic
Comment options

@12joan
Comment options

@fbolcic
Comment options

Answer selected by zbeyens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants