import React from 'react'; import ReactDOM from 'react-dom'; import io from 'socket.io-client'; import Board from './board'; import './index.css'; const ENDPOINT = "http://localhost:4001"; class NameForm extends React.Component { constructor(props) { super(props); this.state = {value: ''}; this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.onSubmit = props.onSubmit; } handleChange(event) { this.setState({value: event.target.value}); } handleSubmit(event) { this.onSubmit(this.state.value); event.preventDefault(); } render() { return (
); } } class Game extends React.Component { constructor(props) { super(props); this.state = { board: null, socket: io(ENDPOINT), gameKey: null, }; this.state.socket.on("FromAPI", data => { console.log(data); this.setState({ board: null, }); this.setState({ board: ( { console.log("ON MOVE"); this.state.socket.emit("move", this.state.gameKey, move); }}/> ), }); }); } setGameKey(key) { console.log(`Setting gameKey to '${key}'`); this.setState({gameKey: key}); this.state.socket.emit("find", key); } render() { return (
{this.state.gameKey ? this.state.board : }
); } } // ======================================== ReactDOM.render( , document.getElementById('root') );