I have react component like this:
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>
)
}
}
I am using websocket io. In method this.props.socket.on
I want print
this.state = {
visible: false
}
But when I print this variable, I am getting undifined error. How can I read/change/update this.state
values in anonymous method likethis.props.socket.on
?
Thank you for your help!