25 lines
656 B
JavaScript
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 };
|
|
}
|