Skip to content

Instantly share code, notes, and snippets.

@waynelkh
Last active January 24, 2016 19:51
Show Gist options
  • Save waynelkh/93f807533955ff86a54c to your computer and use it in GitHub Desktop.
Save waynelkh/93f807533955ff86a54c to your computer and use it in GitHub Desktop.
Some issue with javascript bind
import React from 'react';
import MenuItem from 'material-ui/lib/menus/menu-item';
class LeftNavBar extends React.Component {
constructor(props) {
super(props);
// this.onMenuListTap = this.onMenuListTap.bind(this);
this.state = {
menuItems: [
{ route: 'list', text: 'List' },
{ route: 'about', text: 'About someone' },
{ route: 'redux', text: 'Redux page' },
{ route: 'not', text: '404 page' },
],
};
}
onMenuListTap(route) {
const { history } = this.context;
history.pushState(null, `/${route}`);
this.setState({ open: !this.state.open });
}
render() {
const menuLists = this.state.menuItems.map((data, index) => {
return (
<MenuItem
key = {index}
onTouchTap={this.onMenuListTap.bind(this, data.route)}
// onTouchTap={this.onMenuListTap(data.route)}
primaryText={data.text}
/>);
});
return (
<div>{menuLists}</div>
);
}
}
module.exports = LeftNavBar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment