harim manager
This commit is contained in:
30
src/lib/hooks/useHistory.js
Normal file
30
src/lib/hooks/useHistory.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
import { GET_HISTORY_LIST } from "@/core/utils/routes";
|
||||
|
||||
export const useHistory = (rowId) => {
|
||||
const requestServer = useRequest();
|
||||
const [historyData, setHistoryData] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!rowId) return;
|
||||
|
||||
const fetchHistory = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await requestServer(`${GET_HISTORY_LIST}/${rowId}`);
|
||||
setHistoryData(response.data.data);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchHistory();
|
||||
}, [rowId]);
|
||||
|
||||
return { historyData, loading, error };
|
||||
};
|
||||
Reference in New Issue
Block a user