diff options
author | eug-vs <eug-vs@keemail.me> | 2020-08-10 11:32:13 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-08-10 11:32:13 +0300 |
commit | a5c7950b65652d105c8eff22d14aeeacade6d31f (patch) | |
tree | bd0c22414d4555ee59e0c44d55b01c2aac924461 /src/containers/Home/Home.tsx | |
parent | f97989967ee0b88a8c64f226a4b28a79eeef5fd2 (diff) | |
download | which-ui-a5c7950b65652d105c8eff22d14aeeacade6d31f.tar.gz |
feat: useSWR for feedbacks
Diffstat (limited to 'src/containers/Home/Home.tsx')
-rw-r--r-- | src/containers/Home/Home.tsx | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/containers/Home/Home.tsx b/src/containers/Home/Home.tsx index 73fa479..203b380 100644 --- a/src/containers/Home/Home.tsx +++ b/src/containers/Home/Home.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React from 'react'; import { useHistory } from 'react-router-dom'; import { Typography, @@ -14,7 +14,7 @@ import { Rating } from '@material-ui/lab'; import { Feedback } from 'which-types'; import { useAuth } from '../../hooks/useAuth'; -import { get } from '../../requests'; +import { useFeedback } from '../../hooks/APIClient'; import ReviewCard from '../../components/ReviewCard/ReviewCard'; import ReviewForm from './ReviewForm'; @@ -41,7 +41,7 @@ const useStyles = makeStyles(theme => ({ })); const Home: React.FC = () => { - const [feedbacks, setFeedbacks] = useState<Feedback[]>([]); + const { data: feedbacks } = useFeedback(); const classes = useStyles(); const history = useHistory(); const { isAuthenticated, user } = useAuth(); @@ -53,12 +53,6 @@ const Home: React.FC = () => { 0 ) / feedbacks.length; - useEffect(() => { - get('/feedback').then(response => { - setFeedbacks(response.data); - }); - }, []); - const handleLetsGo = () => { history.push('/feed'); }; @@ -76,7 +70,7 @@ const Home: React.FC = () => { const Reviews = ( <div className={classes.reviews}> - {feedbacks.map(feedback => <ReviewCard feedback={feedback} />)} + {feedbacks.map((feedback: Feedback) => <ReviewCard feedback={feedback} />)} </div> ); |