react-mentions
react-mentions copied to clipboard
Offer a function to extract mentions from value
There is an onAdd function where we can get the added mentions but there is no onRemove, which is just as needed in most cases.
The second best solution to my awareness is to derive the mentions from the onChange callback. Problem is, one's knowledge of regex expressions must be sufficient to do the job. And in most cases, where we'd like to have the most basic use recovered, one will have to spend quite some time learning regex expressions just to get basics working and only to forget them later on.
Of course there will be many developers comfortable with regexes but this issue would be useful for those who aren't.
I'd like to ask again why you need to know when a mention is removed. We've never needed this functionality in the last years. It would help greatly to understand what you're doing that requires knowledge of when that part of the text is removed.
Appreciate the response! Using Backspace. E.g. user mentions @frontendphil but then decides to "backspace" remove that mention. The idea is to keep track of the mentions and then, "onSubmit" submit both the comment's text and the mentioned users.
I could be wrong but to my current awareness, onAdd is called when user selects a suggestion, then presses Enter but then on "Backspace" these mentions do not get updated from anywhere
An idea is to perhaps just append the list of mentioned identifiers in the onChange handler.
For my use case, this library without the ability to extract the mentioned users, is not sufficient at all.
An idea is to perhaps just append the list of mentioned identifiers in the onChange handler.
@xtrinch The list of all mentioned items is already passed to the onChange handler as 4th argument (see https://github.com/signavio/react-mentions#configuration).
Okay, then that kind of also solves the original poster's problem, doesn't it? I missed that in the documentation completely.
May be worth investing an additional line in the documentation for onChange to make that clearer.
An idea is to perhaps just append the list of mentioned identifiers in the onChange handler.
@xtrinch The list of all mentioned items is already passed to the
onChangehandler as 4th argument (see https://github.com/signavio/react-mentions#configuration).
I think this solves all of the use cases.
@jfschwarz Perhaps one weakness is that if I change the markup, that also affects the object returned in the mentions object in the onChange function. I would like the mentions object to hold the full user object that was sent to the component.
Any other way to solve this perhaps?