react 方法未定义_javascript – React 0.13类方法未定义

所以我从React和ES6开始,并且陷入了非常基础的困境.真的很感激一些帮助.

handleClick()抛出一个错误:

Uncaught TypeError: Cannot read property 'handleClick' of undefined

代码如下

export default class MenuItems extends React.Component {

constructor(props) {

super(props)

this.state = {active: false}

this.handleClick = this.handleClick.bind(this)

}

handleClick() {

this.setState({ active: !this.state.active });

}

render() {

let active = this.state.active

let menuItems = [{text: 'Logo'},{text: 'promo'},{text: 'benefits'},{ text: 'form'}]

return (

{menuItems.map(function(item) {

return

{item.text};

})}

);

}

}

你可能感兴趣的:(react,方法未定义)