Created
June 7, 2018 06:05
-
-
Save tlaitinen/3ae2e9c41679a0e8c8dc9a15c1543abc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| class LinkClickTracker extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| } | |
| componentDidMount() { | |
| const {onClickLink} = this.props; | |
| Array.from(this.refs.div.querySelectorAll('a')).forEach(a => { | |
| a.onclick = async e => { | |
| e.preventDefault(); | |
| await onClickLink(); | |
| window.open(a.href, '_blank'); | |
| }; | |
| }); | |
| } | |
| render() { | |
| const {html} = this.props; | |
| return <div ref='div' dangerouslySetInnerHTML={{__html:html}}/>; | |
| } | |
| } | |
| export default LinkClickTracker; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment