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

67
Vistas
Await for changing state of redux store

In my custom combobox I am changing the items pagination mode onClick like below:

onClick={() => {
        changeState(itemsSelectorType, elements[i]);
        fetchItems(currentPagination, 0);
}}

(itemsSelectorType = currentPagination and elements[i] = 24 or 48)

changeState is changing the currentPagination value in my regex store and then in fetchItems() one of my arguments (currentPagination) is the one from store. The problem is that fetchItems reads the old value of the currentPagination, so I need to await for the changeState function.

I tried something like this but it still reads the old value, f.e. when I am choosing 24 it reads 48, when I am choosing 48 it reads 24.

onClick={async () => {
        await changeState(itemsSelectorType, elements[i]);
        fetchItems(currentPagination, 0);
}}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to get data after pagination mode changed.

There are two options. First of all, you know what currentPagination will look like with the selected elements[i]. You can pass it directly like this.

fetchItems(pagination_value, 0)

Second, you can call fetchItems whenever currentPagination changed. Insert this code instead of calling fetchItems in other place.

 React.useEffect(() => {
      fetchItems(currentPagination, 0)
  }, [currentPagination]);
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