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

140
Visualizações
how to update items object after on onTextChange in searchable dropdown in react native?

I am using react-native-searchable-dropdown for my react native project.

When onTextChange is fired I make a call to my backend with the text the user inputs. Then I set the data I get back (array of objects) in the state:

async inputBrandText (text) {
      const brands = await SearchForBrands(params);
      this.setState((state) => {
          return state.brands = brands
      })
};

In the items element I reference this state array:

<SearchableDropdown
    textInputProps={
        {
            placeholder: "",
            underlineColorAndroid: "transparent",
            style: {
               ...
            },
            onTextChange: text => this.inputBrandText(text)
        }
    }
    items={this.state.brands}
/>

But the items get refreshed one key stroke after it should actually be refreshed. So I think when the onTextChange event is fired, the items object or array is read in. Then I change the this.state.brands object with the data from the backend. But then no update occurs and the items object is not updated. Therefor the old items object is shown.

How can I solve this problem in a class based component?

Thanks!

PS: This is my ComponendDidMount:

async componentDidMount () {
  const brands = await SearchForBrands(params);
  this.setState((state) => {
      return state.showBrandSuggestions = brands
  })
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try this way

Your componentDidMount method should be like

async componentDidMount () {
  const brands = await SearchForBrands(params);
  this.setState({ showBrandSuggestions: brands });
}

Your inputBrandText method should be like

async inputBrandText (text) {
  const brands = await SearchForBrands(params);
  this.setState({ brands: brands });
};
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