1、loading&finally
import {useState} from 'react';
export default function useRequestWithLoading() {
const [loading, setLoading] = useState<boolean>(false);
const executerRequest = async(fn: ()=> Promise<void>) => {
setLoading(true);
try {
await fn();
} finally {
setLoading(false);
}
};
return {loading, executerRequest};
}