Code Monkey home page Code Monkey logo

Comments (5)

aiphton avatar aiphton commented on July 29, 2024

Upon debugging, I discovered that the onEditorChange function isn't triggered after invoking uploadImages(). Despite implementing a method to update the body state, the body remains unchanged.

Here's how I integrate TinyMCE as a component in my form:

<TinyEditorComponent
  onInit={(evt, editor) => (editorRef.current = editor)}
  init={{
    content_style: 'body { font-size:14px };',
    height: '100vh',
  }}
  onEditorChange={onEditorChange}
  initialValue={text}
/>

Here, the text value in the initialValue prop is simply a state derived from data retrieved from the database.

And here's the method I've implemented:

const onEditorChange = (newContent) => {
  setData('body', newContent);
  console.log("Body changed:", newContent);
};

This method simply updates the state of the body, which is later sent via the request. Note that I'm using the setData function from the InertiaJS userForm hook, but I've also experimented with a conventional useState hook from React with the same outcome: the state data isn't updated.

Additionally, I have to manually invoke the onEditorChange method because TinyMCE doesn't trigger it automatically after uploadImages() completes. So, the submission process looks something like this:

const submit = (e) => {
  e.preventDefault();

  editorRef.current.uploadImages().then((uploadResults) => {
    const updatedContent = editorRef.current.getContent();
    onEditorChange(updatedContent);
  }).then(() => {
    // Additional actions after image upload
  });
};

from tinymce-react.

aiphton avatar aiphton commented on July 29, 2024

I resolved the issue through sending the updatedContent immediatly with the help of the interiaJS router and not depending on the state of data.body state.

from tinymce-react.

TheSpyder avatar TheSpyder commented on July 29, 2024

Apologies, this should've been moved to our React integration. Not updating the state after image upload might be a bug, so I'm reopening it and moving it over.

from tinymce-react.

aiphton avatar aiphton commented on July 29, 2024

If you need any more details or informations feel free to ask.

from tinymce-react.

danoaky-tiny avatar danoaky-tiny commented on July 29, 2024

Internal ref: INT-3289

from tinymce-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.