29 lines
660 B
TypeScript
29 lines
660 B
TypeScript
/* eslint-disable import/no-unresolved */
|
|
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
import { getDevisList } from "../features/devis/thunk";
|
|
|
|
|
|
export function useDevis() {
|
|
const dispatch = useDispatch<any>();
|
|
const status = useSelector((state: any) => state.devis.status);
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const load = async () => {
|
|
if (status === "idle") {
|
|
setLoading(true);
|
|
await dispatch(getDevisList()).unwrap();
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
load();
|
|
}, [dispatch, status]);
|
|
|
|
return { loading, status };
|
|
}
|