Files
PIbd-22_Ulybin_A.A._Interne…/src/hooks/useProfile.jsx
2025-05-23 22:33:12 +02:00

25 lines
656 B
JavaScript

import { useState, useEffect } from "react";
export default function useProfile() {
const [profile, setProfile] = useState(null);
useEffect(() => {
fetch('http://localhost:5000/profile')
.then(res => res.json())
.then(setProfile);
}, []);
const updateProfile = async (newProfile) => {
// PATCH или PUT — по ситуации
const res = await fetch('http://localhost:5000/profile', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(newProfile)
});
const updated = await res.json();
setProfile(updated);
};
return { profile, updateProfile };
}