question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update React app state from React Quill content element node on click

See original GitHub issue

I want to allow a specific element in the body of a React Quill editor to update the app context on click.

How can I do it?

Here is the custom blot I’ve made:

/* Mention blot config
  ====================== */
class MentionBlot extends BlockEmbed {
  static create(data) {
    const node = super.create();
    const denotationChar = document.createElement("span");
    denotationChar.className = "ql-mention-denotation-char";
    denotationChar.innerHTML = data.denotationChar;
    node.appendChild(denotationChar);
    node.innerHTML += data.value;
    return MentionBlot.setDataValues(node, data);
  }

  static setDataValues(element, data) {
    const domNode = element;
    Object.keys(data).forEach((key) => {
      domNode.dataset[key] = data[key];
    });
    return domNode;
  }

  static value(domNode) {
    return domNode.dataset;
  }
}

MentionBlot.blotName = "mentionCustom";
MentionBlot.tagName = "span";
MentionBlot.className = "mention";

Quill.register("formats/mentionCustom", MentionBlot);

And here is a screenshot of the elements in question:

image

Thank you 😃

Ticket due diligence

  • I have verified that the issue persists under ReactQuill v2.0.0-beta.2
  • I can’t use the beta version for other reasons

ReactQuill version

  • master
  • v2.0.0-beta.2
  • v2.0.0-beta.1
  • 1.3.5
  • 1.3.4 or older
  • Other (fork)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
raw-brtcommented, Sep 1, 2020

Thank you very much, Alex.

I’ll give it a try.

Thank you.

Best, Roberto.

0reactions
alexkrolickcommented, Sep 1, 2020

Closing as this isn’t an issue with the library itself

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change the state of react component on click?
We have to set initial state value inside constructor function and set click event handler of the element upon which click, results in...
Read more >
Update a component's state on Click in React | bobbyhadz
Update a component's state on Click in React #. To update a component's state on click, add an onClick prop to an element...
Read more >
react-quill - npm
Start using react-quill in your project by running `npm i react-quill`. ... override the content whenever value differs from current state.
Read more >
Why can't I get react-quill input to reset after post is submitted
I would try to use value prop for this one since it is a controlled component. <ReactQuill theme='snow' value={comment} onChange={value ...
Read more >
Getting Started with Rich Text Editors in React - Bits and Pieces
Head to your App.js file and feel free to clear everything out of there. Then we'll import the ReactQuill component, as well as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found