Skip to content

Instantly share code, notes, and snippets.

@herbert1228
Created January 30, 2019 11:29
Show Gist options
  • Save herbert1228/859475fda816b951a8383b4da083044d to your computer and use it in GitHub Desktop.
Save herbert1228/859475fda816b951a8383b4da083044d to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import {connection} from './interface/connection'
export default class App extends React.Component {
state = {
counter: 0
}
componentDidMount() {
connection.connect("ws://localhost:8500")
}
handleAddCall = async () => {
const result = await connection.call("add", 1)
this.setState({counter: result})
}
handleSubstractCall = async () => {
const result = await connection.call("substract", 1)
this.setState({counter: result})
}
render() {
return (
<div>
<button onClick={this.handleAddCall}>+</button>
<h3>{this.state.counter}</h3>
<button onClick={this.handleSubstractCall}>-</button>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment