Created
January 30, 2019 11:29
-
-
Save herbert1228/859475fda816b951a8383b4da083044d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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