Skip to content

Commit

Permalink
#50 Add popularTravelers.js with function to get from api
Browse files Browse the repository at this point in the history
  • Loading branch information
SandraBergstrom committed Jun 28, 2023
1 parent 3ce36b8 commit 26be736
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/pages/travelers/PopularTravelers.js
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;

0 comments on commit 26be736

Please sign in to comment.