當我嘗試讀取套接字回調函數內我的道具,它拋出一個錯誤:如何閱讀socket.io回調中的道具?
componentWillMount(){
console.log(this.props.username); // works
this.props.socket.on('question', function(){
console.log(this.props.username); //prints Cannot read property 'username' of undefined
}
});
}
我怎樣才能解決這個問題?