added edit card and get number

This commit is contained in:
SlimusMinus
2026-05-29 01:16:45 +03:00
parent 684ce8f56b
commit 5198e284a3
6 changed files with 175 additions and 89 deletions

View File

@@ -0,0 +1,28 @@
import { useState } from "react";
import { API_URL } from "../config/constants";
export function useUpdatePost() {
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const updateAd = async (id, payload) => {
setLoading(true);
setError("");
try {
const res = await fetch(`${API_URL}/api/v1/posts/${id}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
if (!res.ok) throw new Error(`Ошибка ${res.status}`);
return await res.json();
} catch (err) {
setError(err.message || "Не удалось сохранить");
return null;
} finally {
setLoading(false);
}
};
return { updateAd, loading, error };
}