refactor: env detail
This commit is contained in:
@@ -84,11 +84,12 @@ export function useQueryDataList<ListItem, Params = any>(option: {
|
||||
|
||||
export function useQueryData<Detail, Params = any>(option: {
|
||||
key: string;
|
||||
delay?: number;
|
||||
fetchDetail: (params: Params, options?: any) => Promise<Detail>;
|
||||
getData?: (response: Detail) => any;
|
||||
errorMsg?: string;
|
||||
}) {
|
||||
const { key, fetchDetail, getData, errorMsg } = option;
|
||||
const { key, fetchDetail, getData, errorMsg, delay } = option;
|
||||
const axiosTokenRef = useRef<CancelTokenSource | null>(null);
|
||||
const [detailData, setDetailData] = useState<Detail>({} as Detail);
|
||||
|
||||
@@ -105,6 +106,12 @@ export function useQueryData<Detail, Params = any>(option: {
|
||||
...(extra || {})
|
||||
});
|
||||
|
||||
if (delay) {
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, delay);
|
||||
});
|
||||
}
|
||||
|
||||
setDetailData(getData ? getData(res) : res);
|
||||
|
||||
return res;
|
||||
|
||||
Reference in New Issue
Block a user