Skip to content

Commit

Permalink
#25 Add handleFollow function and pass to setTravelerDataContext
Browse files Browse the repository at this point in the history
  • Loading branch information
SandraBergstrom committed Jun 29, 2023
1 parent 75ec0ee commit 7bb10c8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/contexts/TravelerDataContext.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useContext, useEffect, useState } from "react";
import { axiosReq } from "../api/axiosDefaults";
import { axiosReq, axiosRes } from "../api/axiosDefaults";
import { useCurrentUser } from "./CurrentUserContext";

export const TravelerDataContext = createContext();
Expand All @@ -17,6 +17,16 @@ export const TravelerDataProvider = ({ children }) => {
const { popularTravelers } = travelerData;
const currentUser = useCurrentUser();

const handleFollow = async (clickedTraveler) => {
try {
const {data} = await axiosRes.post('/followers/', {
followed: clickedTraveler.id
})
} catch (err) {
console.log(err)
}
}

useEffect(() => {
const handleMount = async () => {
try {
Expand All @@ -37,7 +47,7 @@ export const TravelerDataProvider = ({ children }) => {

return (
<TravelerDataContext.Provider value={travelerData}>
<SetTravelerDataContext.Provider value={setTravelerData}>
<SetTravelerDataContext.Provider value={{setTravelerData, handleFollow}}>
{children}
</SetTravelerDataContext.Provider>
</TravelerDataContext.Provider>
Expand Down

0 comments on commit 7bb10c8

Please sign in to comment.