unlayer / react-email-editor

Drag-n-Drop Email Editor Component for React.js
https://unlayer.com/embed
MIT License
4.51k stars 728 forks source link

Error while trying to registerCallback #374

Closed M0hammedImran closed 8 months ago

M0hammedImran commented 9 months ago

When I try to registerCallback for selectImage I see the following error on the UI. Screenshot from 2023-11-23 13-11-51

This is the code used to registerCallback

editor.registerCallback("selectImage", (file, done) => {
  this.setState({ openImageSelectionModal: true });
  this.done = done;
});

And when image is selected, I call done callback

this.done({ url: data });

After calling done things seem to work as usual.

brunolemos commented 9 months ago

Thanks for reporting @M0hammedImran. While that is not fixed, you can use this workaround:

unlayer.registerCallback("selectImage", async (file) => {
  const thiss = this;

  return new Promise((resolve) => {
    thiss.done = resolve;
  });
});
M0hammedImran commented 8 months ago

Thanks for reporting @M0hammedImran. While that is not fixed, you can use this workaround:

unlayer.registerCallback("selectImage", async (file) => {
  const thiss = this;

  return new Promise((resolve) => {
    thiss.done = resolve;
  });
});

Thanks @brunolemos, this worked for me.

brunolemos commented 8 months ago

@M0hammedImran we have released a fix. please revert back to your original code instead of the workaround. thanks!