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

Error: Error: There was an error fetching your data #20

Closed siskut closed 5 years ago

siskut commented 5 years ago

Hi,

I am using your package and so happy it's working. But when i changed the value of fetchDataUrl, like this:

<Autocomplete style={styles.input} scrollToInput={ev => {}} handleSelectItem={(item, id) => this.handleSelectItem(item, id)} onDropdownClose={() => {}} onDropdownShow={() => {}} fetchDataUrl={this.state.people} minimumCharactersCount={1} highlightText valueExtractor={item => item.name} rightContent rightTextExtractor={item => item.id} /> the warning show WhatsApp Image 2019-08-18 at 15 39 14

this is the function to get people from my api async function getPeopleFromServer(){ try{ let response = await fetch('http://localhost:3000/people/all'); let responseJson = response.json(); return responseJson; } catch(error){ console.log('Error is: ', error); } }

my state people contains like below

[ { id: '123a', name: 'James' }, { id: 456'b', name: 'George' }, { id: '789c', name: 'Edward' }, { id: '00d', name: 'Jhon' } ]

Do you know what happen? I am so pleasure for your help.

maxkordiyak commented 5 years ago

@siskut You have fixed array of items in your state, you should not use fetchDataUrl, just pass data={this.state.items} as described here

siskut commented 5 years ago

i've tried that. But a new warning says 'TypeError:undefined is not an object (evaluating 'valueExtractor(item).toLowerCase')'

siskut commented 5 years ago

Yey! It's fixed. The solution is {this.state.items} into a variabel. Thankyou!