diff options
author | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-14 20:54:02 +0300 |
---|---|---|
committer | ilyayudovin <ilyayudovin123@gmail.com> | 2020-06-14 20:54:02 +0300 |
commit | 987c050faa5353ae2f250d82055d6685fefa58f7 (patch) | |
tree | d4c40608f40ed27a7d8cb908cdae225bb86e50ae /src/pages/ProfilePage/ProfilePage.tsx | |
parent | 65e41d1d8a3844a6d7268340f5d88b5957e2355d (diff) | |
download | which-ui-987c050faa5353ae2f250d82055d6685fefa58f7.tar.gz |
add useEffect to get requests
Diffstat (limited to 'src/pages/ProfilePage/ProfilePage.tsx')
-rw-r--r-- | src/pages/ProfilePage/ProfilePage.tsx | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/pages/ProfilePage/ProfilePage.tsx b/src/pages/ProfilePage/ProfilePage.tsx index 1dd71d3..984fb1e 100644 --- a/src/pages/ProfilePage/ProfilePage.tsx +++ b/src/pages/ProfilePage/ProfilePage.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState,useEffect } from 'react'; import { User, Poll } from '../../types'; import ProfileInfo from './ProfileInfo'; import Feed from '../../components/Feed/Feed'; @@ -13,13 +13,18 @@ const ProfilePage: React.FC<PropTypes> = ({ logOut, id }) => { const [userInfo, setUserInfo] = useState<User>(); const [polls, setPolls] = useState<Poll[]>([]); - get(`/users/${id}`).then(response => { - setUserInfo(response.data); - }); + useEffect(() => { + get(`/users/${id}`).then(response => { + setUserInfo(response.data); + }); + },[]); + + useEffect(() => { + get(`/profiles/${id}`).then(response => { + setPolls(response.data); + }); + },[]); - get(`/profiles/${id}`).then(response => { - setPolls(response.data); - }); return ( <> |