2020-01-08 07:18:08 +00:00
|
|
|
import React, {useState} from 'react';
|
2020-01-07 20:19:11 +00:00
|
|
|
import './App.scss';
|
2020-01-07 21:03:59 +00:00
|
|
|
import config from './config';
|
2020-01-07 20:19:11 +00:00
|
|
|
|
2020-01-08 07:18:08 +00:00
|
|
|
import socketIOClient from 'socket.io-client';
|
|
|
|
export const socket = socketIOClient(config.apiAddress);
|
|
|
|
|
2020-01-07 20:19:11 +00:00
|
|
|
function App() {
|
2020-01-08 07:18:08 +00:00
|
|
|
const [fetchData, setFetchData] = useState();
|
|
|
|
const [socketData, setSocketData] = useState();
|
|
|
|
fetch(config.apiAddress).then(res => res.text()).then(data => setFetchData(data));
|
|
|
|
socket.emit('connect');
|
|
|
|
socket.on('connected', data => setSocketData(data.message));
|
2020-01-07 20:19:11 +00:00
|
|
|
return (
|
|
|
|
<div className="App">
|
|
|
|
<h1>React Boilerplate</h1>
|
2020-01-08 07:18:08 +00:00
|
|
|
{fetchData ? <p>{fetchData}</p> : <></>}
|
|
|
|
{socketData ? <p>{socketData}</p> : <></>}
|
2020-01-07 20:19:11 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|