import * as React from 'react';

export default class Counter extends React.Component {
  state = {
    count: 0
  };

  increment = () => {
    this.setState({
      count: (this.state.count + 1)
    });
  };

  startConnection = () => {
      const ws = new WebSocket("ws://localhost:5000");
      ws.onopen = (event : Event)=>{
          console.log("onopen");
          ws.send("Messgage from client");
      }
      ws.onmessage = (event : MessageEvent) =>{
          console.log(event.data);
      }
  };

  render () {
    return (
      <div>
        <h1>{this.state.count}</h1>
        <button onClick={this.startConnection}>Start Connection</button>
      </div>
    );
  }
}