maxkordiyak / react-native-dropdown-autocomplete

Autocomplete input with dropdown modal component for React native. Useful for pages with multiple autocomplete's.
MIT License
100 stars 51 forks source link

Consult API by condition #25

Open pixsolution opened 5 years ago

pixsolution commented 5 years ago

Hi there! I need to consult two api within each condition that I have in the autocomplete, but it doesn't take the second one, I worked the api out of autocomplete and in the handleSelectItem = {(item, index) => {this.state.user}} I passed the state of the api but I need to check another api, that is, two api for each condition? how would it be done?

  fetchDatasearch = async () => {
    const response = await fetch(
      `https://www.mydomain.com/api/searchuserL?email=${searchTerm}`
    );
    const search = await response.json();
    console.log("search.user", search.user);
    this.setState({ user: search.user });
       name.setText(Name);
       lastname.setText(LastName);
       telephone.setText(telephone);

    //console.log("user", this.state.user); 
  };
   componentDidMount() {
    this.fetchDatasearch();

   }

    <Autocomplete
                    key={shortid.generate()}
                    style={baseStyles.input}
                    scrollToInput={ev => { }}
                    handleSelectItem={(item, index) => {this.state.user}}
                    onDropdownClose={() => { }}
                    onDropdownShow={() => { }}
                    minimumCharactersCount={1}
                    highlightText
                    valueExtractor={item => item.email || ( item.name||item.lastname)}
                    rightContent
                    rightTextExtractor={item => item.properties}
                    placeholder={this.state.checked ? 'Email' : 'Search by Name, LastName'}
                    fetchData={async (searchTerm) => {

                      if (this.state.checked == 1) {
                          const response = await fetch( `https://www.mydomain.com/api/searchuserL?email=${searchTerm}`);
                        return await response.json();
                      /*if (response == true)
                          const response2 = await fetch( `https://www.mydomain.com/api/searchuser?email=${searchTerm}`);
                          return await response2.json();
                          name.setText(Name);
                          lastname.setText(LastName);
                          telephone.setText(telephone);*/

                      } else {
                        const response = await fetch(`https://mydomain.com/api/searchpatientL?patient=${searchTerm}`);
                        return await response.json();
                      }