connect socket
This commit is contained in:
parent
6171fa85c5
commit
fb30588566
2 changed files with 15 additions and 6 deletions
|
@ -1,14 +1,21 @@
|
||||||
import React from 'react';
|
import React, {useState} from 'react';
|
||||||
import './App.scss';
|
import './App.scss';
|
||||||
import config from './config';
|
import config from './config';
|
||||||
|
|
||||||
|
import socketIOClient from 'socket.io-client';
|
||||||
|
export const socket = socketIOClient(config.apiAddress);
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
let fetchData = {};
|
const [fetchData, setFetchData] = useState();
|
||||||
fetch(config.apiAddress).then(res => {console.log(res);fetchData = res.body}).then(() => console.log(fetchData))
|
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));
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<h1>React Boilerplate</h1>
|
<h1>React Boilerplate</h1>
|
||||||
{fetchData ? <p></p> : <></>}
|
{fetchData ? <p>{fetchData}</p> : <></>}
|
||||||
|
{socketData ? <p>{socketData}</p> : <></>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
const production = {
|
const production = {
|
||||||
apiAddress: null
|
apiAddress: null,
|
||||||
|
endpoint: null
|
||||||
}
|
}
|
||||||
|
|
||||||
const development = {
|
const development = {
|
||||||
apiAddress: 'http://localhost:8000'
|
apiAddress: 'http://localhost:8000',
|
||||||
|
endpoint: 'http://localhost:3000'
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = process.env.REACT_APP_ENVIRONMENT === 'production'
|
const config = process.env.REACT_APP_ENVIRONMENT === 'production'
|
||||||
|
|
Loading…
Reference in a new issue