Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!