Added useLoad made it to 25:18 in the video for Act14.

This commit is contained in:
bobbert committed 2025-12-04 23:15:46 +00:00
1 parent b9d99f337c
commit 57369791a4
1 file changed
+28
+28
View File
@@ -0,0 +1,28 @@
import {useEffect, useState} from "react";
import API from "./API";
const useLoad = (loadEndpoint) => {
// State ----------------------
const [records, setRecords] = useState([]);
const [isLoading, setIsLoading] = useState(true);
// Loader ----------------------
const loadRecords = async (endpoint) => {
const response = await API.get(endpoint);
setIsLoading(false);
if (response.isSuccess) setRecords(response.result);
};
useEffect(() => {
loadRecords(loadEndpoint);
}, []);
// return ----------------------
return[records, setRecords, isLoading, loadRecords];
};
export default useLoad;