From 57369791a4d2d7bfda2922a4be8f122972d7574a Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Thu, 4 Dec 2025 23:15:46 +0000 Subject: [PATCH] Added useLoad made it to 25:18 in the video for Act14. --- src/components/API/useLoad.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/components/API/useLoad.js diff --git a/src/components/API/useLoad.js b/src/components/API/useLoad.js new file mode 100644 index 0000000..d4ec896 --- /dev/null +++ b/src/components/API/useLoad.js @@ -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; \ No newline at end of file