import React, { useEffect, useReducer } from 'react'; import { Switch, Route, BrowserRouter as Router } from 'react-router-dom'; import MainWrapper from './pages/Layout/MainWrapper/MainWrapper'; import { stateReducer } from './reducers/reducer'; import { initState } from './reducers/init/reducer.init'; import indexServices from './services/api/indexServices'; import './App.scss'; function App() { const [ state, dispatch ] = useReducer( stateReducer, {}, initState ); useEffect(() => { const fetchIndexAPI = async () => { const response = await indexServices.indexService(); if (response) { const action = { type: 'INDEX', message: 'SET_USER', body: response } dispatch(action) } } fetchIndexAPI(); }, [ ]) useEffect(() => { const socketConnect = () => { if (state.connect.type) return; dispatch({type:'SOCKET', message: 'LAUNCH', body:{nsp:'', dispatch}}); } socketConnect(); return () => dispatch({type: 'SOCKET', message: 'DISCONNECT', body: {}}); }, [ state.connect ]) return (
{state.user.username ? : }

{state.connect.type ? '✓' : ' ⃠'}

); } export default App;