mirror of
https://github.com/mudabbir-ahmad/Project-MAD-crudler.git
synced 2026-10-07 20:40:20 +00:00
28 lines
677 B
JavaScript
28 lines
677 B
JavaScript
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; |