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