From 3cff0821a8989afca1effb5420d8d0d55d513dbf Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 14 Jun 2020 15:35:04 +0300
Subject: fix: fetch user correctly

---
 src/index.tsx | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

(limited to 'src/index.tsx')

diff --git a/src/index.tsx b/src/index.tsx
index 1362544..0855038 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
 import ReactDOM from 'react-dom';
 import {
   createMuiTheme,
@@ -15,6 +15,7 @@ import ProfileInfo from './ProfileInfo/ProfileInfo';
 
 import SignInForm from './Form/SignInForm';
 import { User } from './types';
+import { get } from './requests';
 
 const theme = createMuiTheme({
   palette: {
@@ -37,6 +38,15 @@ const App: React.FC = () => {
   const [user, setUser] = React.useState<User | undefined>();
   const classes = useStyles();
 
+  useEffect(() => {
+    const userId = localStorage.getItem('userId');
+    if (userId) {
+      get(`/users/${userId}`).then(response => {
+        setUser(response.data);
+      });
+    }
+  }, []);
+
   return (
     <ThemeProvider theme={theme}>
       <CssBaseline />
-- 
cgit v1.2.3

