Skip to content

Infinite request loop when prefetching data from URL that returns error #3942

Open
@KostkaBrukowa

Description

@KostkaBrukowa

Hey!
I've encountered this problem lately and I was wondering what could I do with that.

I have this piece of code

import * as React from 'react'
import { useGetPokemonByNameQuery } from './services/pokemon'

export default function App() {
  const { isLoading } = useGetPokemonByNameQuery('bulbasaur')

  return (
    <div className="App">
       {isLoading ? 'Loading...' : <Pokemon name={'bulbasaur'} />} 
    </div>
  )
}

export const Pokemon = ({ name }: { name: string }) => {
  const {} = useGetPokemonByNameQuery(name)

  return (
    <div>
      Pokemon
    </div>
  )
}

Link to codesanbox: LINK

Basically the theme here is:

  1. I want to preload some data, therefore I use useGetPokemonByNameQuery in parent component
  2. When the data is loading I'm not rendering child component.
  3. When the data is preloaded I want to display the data in child component using the same hook

And everything works well when the request was succesful.
Unfortunately when the request fails continuously (like in the sandbox there is wrong URL) there is infinite loop of requests coming from RTK query

I was wondering if you could help me with solution here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions