Spaces:
Paused
Paused
File size: 851 Bytes
a0fda44 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import { useEffect } from "react";
import useFetch from "./useFetch";
import { useSelector, useDispatch } from "react-redux";
import { userActions } from "../store/userSlice";
const useSettings = () => {
const dispatch = useDispatch();
const user = useSelector((state) => state.userReducer.user);
const { reqFn: getProfile } = useFetch(
{ method: "GET", url: "/profile" },
(data) => {
dispatch(userActions.setUser({ user: data.data.user }));
}
);
const { reqFn: updateProfile, reqState: updateProfileState } = useFetch(
{
method: "PATCH",
url: "/profile",
},
(data) => {
dispatch(userActions.setUser({ user: data.data.user }));
}
);
useEffect(() => {
getProfile();
}, []);
return {
user,
updateProfile,
updateProfileState,
};
};
export default useSettings;
|