mirror of
https://github.com/mudabbir-ahmad/Project-MAD-crudler.git
synced 2026-10-07 20:40:20 +00:00
Added useLoad made it to 25:18 in the video for Act14.
This commit is contained in:
1 parent
b9d99f337c
commit
57369791a4
1 file changed
+28
@@ -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;
|
||||
Reference in new issue
Block a user