I am trying to make a socket connection to my backend through my front end, but sme successfully
I declared my socket in my state and then opened the connection, but I don't know why this error:
code:
class App extends Component {
constructor(props, context){
super(props, context);
this.state = {
queue: '',
socket: null
};
}
componentDidMount() {
// io() not io.connect()
this.state.socket = io('http://localhost:9000');
this.state.socket.on('queue', (queue) => {
this.setState({
queue
})
});
this.state.socket.open();
}
componentWillUnmount() {
this.state.socket.close();
}
render() {
return (
<div>
<p> Queue: {this.state.queue} </p>
</div>
)
}
}