Update React app state from React Quill content element node on click
See original GitHub issueI 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:
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:
- Created 3 years ago
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you very much, Alex.
I’ll give it a try.
Thank you.
Best, Roberto.
Closing as this isn’t an issue with the library itself