【发布时间】:2022-12-07 01:53:03
【问题描述】:
我在 React Typescript 中发出了 API 请求。在代码中,没有数据,因此 API 返回以下内容:this request has no response data available。
当我尝试验证响应时,在下面的最后一行代码中,它会打印空的支付响应,但不会输入 if 语句,控制台日志语句为loading error。
为什么不进入if语句?我需要在 if 语句中运行一些代码。
应用程序接口
export const getPaymentsById = (
paymentId: number,
): Promise<PaymentByIdResponse> =>
kfetch(`/billing-payments-ui/api/payments/${paymentId}`);
export type PaymentByIdResponse = {
paymentId?: number;
paymentAmount?: number;
postingDate?: string;
paymentMethod?: string;
confirmationNumber?: string;
paymentDescription?: string;
};
const paymentResponse = await getPaymentsById(paymentIdNumber);
console.log('paymentResponse', paymentResponse);
if (paymentResponse == null) {
console.log('loading error');
setIsLoadingError(true);
....
}
【问题讨论】:
标签: javascript reactjs typescript