react-html-parser
react-html-parser copied to clipboard
conversion of attached event handlers on html strings
For instance attached onClick event is not properly converted
Posting this because I couldn't find a solution for this on issues.
I created a little workaround, maybe you could use this. I need to click on a <span>
. I get something like <a href=''>username</a>
for that node and a part of the transform function that handles that <a>
tag looks like this:
const transform = (node: any, index: number) => {
...
if (node.type === 'tag' && node.name === 'a') {
return (
<span
onClick={() => onUserClick(node.children[0].data)}
>
{processNodes(node.children, transform)}
</span>
);
}
return convertNodeToElement(node, index, transform);
};