-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#50 Add popularTravelers.js with function to get from api
- Loading branch information
1 parent
3ce36b8
commit 26be736
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import appStyles from "../../App.module.css"; | ||
import Container from "react-bootstrap/Container"; | ||
import { axiosReq } from "../../api/axiosDefaults"; | ||
import { useCurrentUser } from "../../contexts/CurrentUserContext"; | ||
|
||
const PopularTravelers = () => { | ||
const [travelerData, setTravelerData] = useState({ | ||
pageTraveler: { results: [] }, | ||
popularTravelers: { results: [] }, | ||
}); | ||
const { popularTravelers } = travelerData; | ||
const currentUser = useCurrentUser() | ||
|
||
useEffect(() => { | ||
const handleMount = async () => { | ||
try { | ||
const { data } = await axiosReq.get( | ||
"/travelers/?ordering=-followers_count" | ||
); | ||
setTravelerData((prevState) => ({ | ||
...prevState, | ||
popularTravelers: data, | ||
})) | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
}; | ||
|
||
handleMount() | ||
}, [currentUser]); | ||
|
||
return ( | ||
<Container className={appStyles.Container}> | ||
<p>Most followed travelers</p> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default PopularTravelers; |