Javascript React Redux调试道具
我是新手,我一直在尝试练习ajax调用,但我无法让我的道具功能正常工作。我能够从facebook响应中获取json数据,但我无法将其传递给操作。为了简洁起见,我删减了代码 用户列表.jsJavascript React Redux调试道具,javascript,reactjs,redux,react-redux,axios,Javascript,Reactjs,Redux,React Redux,Axios,我是新手,我一直在尝试练习ajax调用,但我无法让我的道具功能正常工作。我能够从facebook响应中获取json数据,但我无法将其传递给操作。为了简洁起见,我删减了代码 用户列表.js class UserList extends Component { responseFacebook(response) { console.log(response); this.props.login(response) } render() {
class UserList extends Component {
responseFacebook(response) {
console.log(response);
this.props.login(response)
}
render() {
return (
<div>
<FacebookLogin
appId="mysecretappid10239"
autoLoad={true}
fields="name,email,picture"
scope="public_profile,user_friends,user_actions.books"
callback={this.responseFacebook}
/>
</div>
);
}
}
function mapStateToProps(state) {
return {
users: state.users.data,
fetched: state.users.fetched
};
}
function matchDispatchToProps(dispatch){
return bindActionCreators({login: login}, dispatch);
}
export default connect(mapStateToProps, matchDispatchToProps)(UserList);
这是我得到的错误:
Uncaught TypeError: Cannot read property 'login' of undefined
问题:
Uncaught TypeError: Cannot read property 'login' of undefined
如何在没有错误的情况下正确执行此模式?将
回调={this.responseFacebook}
更改为回调={this.responseFacebook.bind(this)}
或者,最好将其绑定到构造函数中
class UserList extends Component {
constructor(){
super();
this.responseFacebook = this.responseFacebook.bind(this);
}
responseFacebook(response) {
console.log(response);
this.props.login(response)
}
...