Last active
July 15, 2019 07:49
-
-
Save mstaicu/4ffe41b6980ad35d82deae4e32582ef0 to your computer and use it in GitHub Desktop.
A React Higher-order Component for sending analytics based on the original post of David Tang for DailyJS
This file contains 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'; | |
export default function(mapPropsToData, WrappedComponent) { | |
return function(props) { | |
function onClick(event) { | |
if (event.target.tagName === 'A') { | |
const data = mapPropsToData ? mapPropsToData(props) : {}; | |
// Process data | |
} | |
} | |
return ( | |
<div onClick={onClick}> | |
<WrappedComponent {...props} /> | |
</div> | |
); | |
}; | |
} |
This file contains 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, { Component } from 'react'; | |
import AnalyticsHOC from './AnalyticsHOC'; | |
class ComponentToWrap extends Component { | |
render() { | |
//... | |
} | |
} | |
export default AnalyticsHOC(function(props) { | |
return { | |
title: props.title, | |
}; | |
}, ComponentToWrap); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment