react-html-parser icon indicating copy to clipboard operation
react-html-parser copied to clipboard

conversion of attached event handlers on html strings

Open JMA12 opened this issue 5 years ago • 1 comments

For instance attached onClick event is not properly converted

JMA12 avatar Mar 26 '19 09:03 JMA12

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);
  };

stevan-borus avatar Jan 18 '22 19:01 stevan-borus