Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE React cursor back to start after typing a key

I'm using TinyMCE-React and when I type my text in the TinyMCE Editor with an initial value, the cursor constantly returns at the start of the text...

import { Editor } from "@tinymce/tinymce-react";

  const [formData, setFormData] = useState({
    title: "",
    text: "",
  });


if (post) {
  setFormData((formData) => ({
    ...formData,
    title: post.title,
    text: post.text,
  }));
}

const { title, text } = formData;

My function :

const textChange = (e) => {
setFormData({ ...formData.text, text: e });   };

My Editor :

    <Editor
      name='text'
      initialValue={text}
      onEditorChange={(e) => textChange(e)}
    />

I think it's because of the "setFormData" but I don't know how can I edit the text with a regular cursor which stays at the end of the text...

like image 768
SanB Avatar asked Dec 15 '25 04:12

SanB


1 Answers

Late answer, but here's the fix: https://github.com/tinymce/tinymce-react/issues/267.

Change initialValue={text} to value={text}.

This is the right setup for using the TinyMCE React component as a "controlled" component: https://www.tiny.cloud/docs/integrations/react/#usingthetinymcereactcomponentasacontrolledcomponent.

like image 200
CBrown77 Avatar answered Dec 16 '25 20:12

CBrown77



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!