Last active
November 23, 2016 15:00
-
-
Save mrcthms/af4051957fadbb7f747e7900cc818cf1 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'; | |
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> | |
); | |
} | |
}); |
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'; | |
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