ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` Uncaught TypeError: this is undefined ``` ``` import React from 'react'; import PropTypes from 'prop-types'; class Profile extends React.Component{ constructor(props){ super(props) this.state = { liked:0 } //this.likedCallback = this.likedCallback.bind(this); } likedCallback(){ let liked = this.state.liked; liked++; this.setState({ liked }) } render(){ return ( <div className="profile-component"> <h1>我的名字{this.props.name}</h1> <h2>我今年{this.props.age}</h2> <button onClick={this.likedCallback}>给我点赞</button> <h2>总点赞数:{this.state.liked}</h2> </div> ) } } Profile.propTypes = { name: PropTypes.string, age: PropTypes.number, // ... define your prop validations }; //Profile.PropTypes = propTypes; export default Profile; ``` ``` import React from 'react'; import PropTypes from 'prop-types'; class Profile extends React.Component{ constructor(props){ super(props) this.state = { liked:0 } this.likedCallback = this.likedCallback.bind(this); } likedCallback(){ let liked = this.state.liked; liked++; this.setState({ liked }) } render(){ return ( <div className="profile-component"> <h1>我的名字{this.props.name}</h1> <h2>我今年{this.props.age}</h2> <button onClick={this.likedCallback}>给我点赞</button> <h2>总点赞数:{this.state.liked}</h2> </div> ) } } Profile.propTypes = { name: PropTypes.string, age: PropTypes.number, // ... define your prop validations }; //Profile.PropTypes = propTypes; export default Profile; ```