Answer the question
In order to leave comments, you need to log in
How to hang onClick on ReactHtmlParser span?
I have a div in which the finished html is transferred, but at the same time I replace some words with links that can be clicked on. And so I cannot hang up the output agent onclick on these words.
The words are found and replaced as they should, the required class is added to them, but the handler is not.
Here is the code
const p = post
let postWithLinks;
for (let i = 0; i < dict.length; i += 1) {
postWithLinks =
p.replace(`${dict[i].title}`, `<span class="dict-post-link" onClick={alert('!')} >${dict[i].title}</span>`)
}
return (
<Fragment >
{ ReactHtmlParser(postWithLinks) }
</Fragment>
)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question