Skip to content

Instantly share code, notes, and snippets.

View mstaicu's full-sized avatar

Mircea Staicu mstaicu

  • Earth
View GitHub Profile
@mstaicu
mstaicu / LoadingEnhancer.js
Last active July 13, 2017 12:30
Loading enhancer Higher-order Component
import React from 'react';
export default function(LoadingComponent, WrappedComponent) {
return function(props) {
return (
{
(props.status === 'LOADING') ? <LoadingComponent /> : <WrappedComponent {...props.data} />
}
)
};
@mstaicu
mstaicu / AnalyticsHOC.js
Last active July 15, 2019 07:49
A React Higher-order Component for sending analytics based on the original post of David Tang for DailyJS
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
}