QuickChess/src/index.js

55 lines
993 B
JavaScript
Raw Normal View History

2020-12-27 20:11:50 -05:00
import React from 'react';
import ReactDOM from 'react-dom';
import io from 'socket.io-client';
import Board from './board';
2020-12-27 20:11:50 -05:00
import './index.css';
const ENDPOINT = "http://192.168.1.7:4001";
2020-12-27 20:11:50 -05:00
class Game extends React.Component {
constructor(props) {
super(props);
this.state = {
board: null,
socket: io(ENDPOINT),
};
this.state.socket.on("FromAPI", data => {
console.log(data);
this.setState({
board: null,
});
this.setState({
board: (
<Board
text={data}
onMove={(move) => {
console.log("ON MOVE");
this.state.socket.emit("move", move);
}}/>
),
});
});
}
2020-12-27 20:11:50 -05:00
render() {
return (
<div className="game">
<div className="game-board">
{this.state.board}
</div>
2020-12-27 20:11:50 -05:00
</div>
);
}
}
// ========================================
ReactDOM.render(
<Game />,
document.getElementById('root')
);