Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

69
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda