Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
onClick is getting triggerd multiple times react ref

I have a download functionality where I am downloading

const csvLink = createRef();

const dropdown = (
  <div onClick={refetch}>
    {safeLabel(messages.csv)}
    <Icon name="pull" />
    {isSuccess ? <CSVLink ref={csvLink} data={data?.data}></CSVLink> : null}
  </div>
);

const onsuccess = (response) => {
  csvLink?.current?.link?.click();
};

const { refetch, data, isSuccess } = useQuery(
  "apicall",
  () => fetchData(headers),
  {
    enabled: false,
    onSuccess: onsuccess
  }
);

So, here when I click on the icon pull that time query gets called and sends me a response which I am passing it to the csvLink and trying to download the csv. Now because of the csvLink?.current?.link?.click(); called in onsuccess of query this refetch is getting called in infinite loop. Where to call this click and how to fix this issue ?

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should use useRef instead of createRef

const csvLink = useRef();

createRef: function creates a new ref every re-render.

useRef: function uses the same ref throughout. It saves it's value between re-renders in a functional component and doesn't create a new instance of the ref for every re-render.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda