T
TanStack15mo ago
afraid-scarlet

infinite loop

Does react query cache the results or error when the api returns an error?. React query custom hook gets called every time when the component is opened if the api is failed previously. Child component also calls the react query hook which I am using to get the data from parent react query call but because the api is failed child also calls api. the code looks like below example. This is causing infinite loop when there is an error customHook. customHook is react query function for fetching data. const ChildComponent = () => { const {data} = customHook(); reutrn <div> Test <div /> } const Parent = () => { const {isLoading, data} = customHook(); return isLoading ? <Loader /> : <ChildComponent /> }
1 Reply
quickest-silver
quickest-silver15mo ago
retryOnMount: false

Did you find this page helpful?