に反応する私はこのようなコンポーネントを反応させていますコンポーネント
import React, { Component } from 'react'
import { Sidebar, Segment, Button, Menu, Image, Icon, Header } from 'semantic-ui-react'
export default class Footer extends Component {
constructor(props) {
super(props)
this.state = {
visible: false
}
this.handleClick = this.handleClick.bind(this);
this.handleClick();
}
handleClick() {
this.props.socket.on('connect', function() {
console.log("PRINT this.state.visible");
console.log('Connected');
});
this.props.socket.on('disconnect', function() {
console.log('Disconnected');
});
}
render() {
return (
<div className='create-task-section'>
"HELLO"
</div>
)
}
}
私はのWebSocketのIOを使用しています。方法this.props.socket.on
で私は
this.state = { visible: false }
を印刷したい。しかし、私は、この変数を印刷するとき、私はundifinedエラーを取得しています。 this.props.socket.on
のような匿名メソッドでthis.state
の値を読み込み/変更/更新するにはどうすればよいですか?
ありがとうございました!
あなたは 'handleClick'メソッドを' bind'するのではなく、無名関数をバインドしてはいけません。 – Bergi
'console.log(" PRINT "、this.state.visible)' not 'console.log(" PRINT this.state.visible ")'を意味すると思いますか? – Bergi