>  Q&A  >  본문

axios를 사용하여 get 요청을 하면 React Query의 .isSuccess 오류가 발생합니다.

<p><br /></p> <pre class="brush:php;toolbar:false;">const searchInvoiceList = async ( plantLoc: 문자열, 송장옵션: 문자열 ) => { 데이터를 보자: InvoiceData[] = []; 액시오스를 기다리다 .get(`${linkURL}inv/getControlList/${plantLoc}/${invoiceOption}`) .then((응답) => { 데이터 = response.data.sqlData; }) .catch((오류) => console.error(오류)); 데이터를 반환합니다. }; const fetchInvoices = useQuery({ 쿼리키: [ "송장데이터", plantLocationOptionChecked.value, voiceOptionChecked.value, ], queryFn: () => 검색송장목록( plantLocationOptionChecked.value, voiceOptionChecked.value ), 활성화됨: 거짓, 재시도: 0, }); if(fetchInvoices.isSuccess) { if (fetchInvoices.data.length === 0) { toast.error("搜索结果为空"); } setFetchedInvoiceData(fetchInvoices.data); } if(fetchInvoices.isError) { console.log(fetchInvoices.error); }</pre> <p>저희는 온클릭 사건에 대해 모두 가지고 있습니다.止无限循环。”如果我去掉<code>setFetchedInvoiceData(fetchInvoices.data);</code>并且数组返回为0,它会触发我的react-hot-toast函数<code>toast.error("搜索结果为空");< ;/code>但然后我会收到警告“지금渲染不同组件(App)时无法更新组件(Ie)”。我做错了什么,如何修复这个问题?</p>
P粉153503989P粉153503989402일 전407

모든 응답(1)나는 대답할 것이다

  • P粉517090748

    P粉5170907482023-08-16 18:54:18

    전체 구성 요소의 코드를 살펴보지 않고 최상의 솔루션을 제공하기는 어렵지만 현재 여기에서는 다음과 같이 모든 재렌더링에서 fetchInvoices.isSuccess上运行条件,解决的最佳方法是将其添加到useEffect를 받고 있는 것을 볼 수 있습니다.

    으아악

    회신하다
    0
  • 취소회신하다