Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何从成功的React查询中获取HTTP响应代码?_Reactjs_Axios_React Query - Fatal编程技术网

Reactjs 如何从成功的React查询中获取HTTP响应代码?

Reactjs 如何从成功的React查询中获取HTTP响应代码?,reactjs,axios,react-query,Reactjs,Axios,React Query,如何从成功的React查询中获取状态代码 这是我的定制挂钩: const validateIban = async (accountId, encodedIban) => { await axios .post(`${CUSTOMER_PORTAL_API}/policy/accounts/${accountId}/iban/${encodedIban}`) }; export function useValidateIban(accountId) { r

如何从成功的React查询中获取状态代码

这是我的定制挂钩:

const validateIban = async (accountId, encodedIban) => {
    await axios
        .post(`${CUSTOMER_PORTAL_API}/policy/accounts/${accountId}/iban/${encodedIban}`)
};

export function useValidateIban(accountId) {
    return useMutation(encodedIban => validateIban(accountId, encodedIban));
}
这就是我使用mutate的钩子的地方:

const validateIbanQuery = useValidateIban(accountId)


validateIbanQuery.mutate(encodeURIComponent(iban), {
        onSuccess: () => {
          ******HERE I WANT THE STATUS CODE (204, 202 e.g.)******
        },
        onError: (error) => {
          if (error.response.status === 400) {
            ....
          }
          if (error.response.status === 403) {
            ....
          }
        }
      })

onSuccess
回调的第一个参数是
AxiosResponse

axios.post(“/api/data”,{text})。然后(响应=>{
console.log(response.status)
return response;//此响应将作为onSuccess的第一个参数传递
});
onSuccess:(数据)=>{
console.log(数据状态);
},
现场演示

这导致数据未定义:(@btrautmann我在配置
axios模拟适配器时没有返回数据,现在应该修复了。您只需返回
axios.post(…)