Skip to content

Instantly share code, notes, and snippets.

@mrcthms
Last active November 23, 2016 15:00
Show Gist options
  • Save mrcthms/af4051957fadbb7f747e7900cc818cf1 to your computer and use it in GitHub Desktop.
Save mrcthms/af4051957fadbb7f747e7900cc818cf1 to your computer and use it in GitHub Desktop.
import React from 'react';
export const Nav = React.createClass({
componentDidMount: function () {
analytics.track('Nav Mounted');
},
handleLogoClick: function (evt) {
evt.preventDefault();
analytics.track('Logo Clicked');
},
render: function () {
var navItems = [
<a href="#">About</a>,
<a href="#">Shop</a>,
<a href="#">Help</a>
];
if (this.props.hasCart) {
navItems.push(
<a href="#">Cart</a>
);
}
return (
<div className="nav">
<a
href="#"
onClick={this.handleLogoClick}>
Logo
</a>
{navItems}
</div>
);
}
});
import React from 'react';
import compose from 'recompose/compose';
import lifecycle from 'recompose/lifecycle';
import withHandlers from 'recompose/withHandlers';
import withProps from 'recompose/withProps';
export var enhance = compose(
withProps(props => {
var navItems = [
<a href="#">About</a>,
<a href="#">Shop</a>,
<a href="#">Help</a>
];
if (props.hasCart) {
navItems.push(
<a href="#">Cart</a>
);
}
return {
navItems
};
}),
withHandlers({
onLogoClick: props => evt => {
evt.preventDefault();
analytics.track('Logo Clicked');
}
}),
lifecycle({
componentDidMount() {
analytics.track('Nav Mounted');
}
})
);
export var Nav = props => (
<div className="nav">
<a
href="#"
onClick={props.onLogoClick}>
Logo
</a>
{props.navItems}
</div>
);
export default enhance(Nav);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment