mirror of
https://git.roussel.pro/telecom-paris/pact.git
synced 2026-02-09 18:40:17 +01:00
connexion a l'api d'avis
This commit is contained in:
32
code/interface_admin/hooks/review.js
Normal file
32
code/interface_admin/hooks/review.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api } from "../config/reviewsApi";
|
||||
|
||||
|
||||
function useReview(reviewId) {
|
||||
const [review, setReview] = useState({});
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(false);
|
||||
|
||||
async function fetchData(id) {
|
||||
const response = await fetch('http://' + api.HOST + `/borne/get_review?id=${id}`)
|
||||
if (response.ok) {
|
||||
const jsonData = await response.json();
|
||||
setReview(jsonData);
|
||||
setLoading(false);
|
||||
setError(false);
|
||||
} else {
|
||||
setError(true);
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (reviewId) {
|
||||
fetchData(reviewId);
|
||||
}
|
||||
}, [reviewId])
|
||||
|
||||
return { review, loading, error }
|
||||
}
|
||||
|
||||
export default useReview;
|
||||
Reference in New Issue
Block a user