import React from 'react'; import io from 'socket.io-client'; export default class App extends React.Component { constructor(props) { super(props); this.state = { socket: io.connect() } } componentDidMount() { this.connect(); } componentWillMount() { document.body.addEventListener('touchmove', function(e){ e.preventDefault(); }); } componentWillUnmount() { this.setState({socket: this.state.socket.removeAllListeners()}); } connect() { let socket = this.state.socket; socket.on('connect', () => { console.log('Connected!'); }); } sendOn() { this.state.socket.emit('update', '1'); console.log('On sent.'); } sendOff() { this.state.socket.emit('update', '0'); console.log('Off sent.'); } render() { return (

Remote Control Lightswitch

this.sendOn()} className="bordered inverted yellow idea huge icon">
this.sendOff()} className="bordered inverted disabled idea huge icon">
); } }