Skip to content

Commit

Permalink
#57 Add currentUser to refetch posts on login/logout
Browse files Browse the repository at this point in the history
  • Loading branch information
SandraBergstrom committed Jul 5, 2023
1 parent d6d4e89 commit edbbb35
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pages/posts/PostsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import NoResults from "../../assets/no-results.png";
import InfiniteScroll from "react-infinite-scroll-component";
import { fetchMoreData } from "../../utils/utils";
import PopularTravelers from "../travelers/PopularTravelers";
import { useCurrentUser } from "../../contexts/CurrentUserContext";

function PostsPage({ message, filter = "" }) {
const [posts, setPosts] = useState({ results: [] });
const [hasLoaded, setHasLoaded] = useState(false);
const { pathname } = useLocation();

const [query, setQuery] = useState("");
const currentUser = useCurrentUser();

useEffect(() => {
const fetchPosts = async () => {
Expand All @@ -40,7 +42,7 @@ function PostsPage({ message, filter = "" }) {
return () => {
clearTimeout(timer);
};
}, [filter, query, pathname]);
}, [filter, query, pathname, currentUser]);

return (
<Row className="h-100">
Expand Down

0 comments on commit edbbb35

Please sign in to comment.