modifs complete
This commit is contained in:
@@ -7,6 +7,7 @@ interface UseCollectionOptions {
|
||||
limit?: number;
|
||||
filter?: Record<string, unknown>;
|
||||
search?: string;
|
||||
referent?: string;
|
||||
}
|
||||
|
||||
interface CollectionResponse<T> {
|
||||
@@ -27,7 +28,7 @@ export function useCollection<T = Record<string, unknown>>(
|
||||
const [total, setTotal] = useState(0);
|
||||
const [totalPages, setTotalPages] = useState(0);
|
||||
|
||||
const { page = 1, limit = 20, filter = {}, search } = options;
|
||||
const { page = 1, limit = 20, filter = {}, search, referent } = options;
|
||||
|
||||
// Mémoriser la chaîne JSON du filtre pour éviter les re-renders inutiles
|
||||
const filterString = useMemo(() => JSON.stringify(filter), [filter]);
|
||||
@@ -43,6 +44,9 @@ export function useCollection<T = Record<string, unknown>>(
|
||||
if (search) {
|
||||
params.append("search", search);
|
||||
}
|
||||
if (referent) {
|
||||
params.append("referent", referent);
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`/api/collections/${collectionName}?${params}`
|
||||
@@ -59,7 +63,7 @@ export function useCollection<T = Record<string, unknown>>(
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [collectionName, page, limit, filterString, search]);
|
||||
}, [collectionName, page, limit, filterString, search, referent]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
|
||||
Reference in New Issue
Block a user