I am trying to do autocomplete input but in my function onTextChange i have little problem my values is ok ( console.log ) but lenght of my values is still undefined.
I tried to inject all values to another strings or arrays but nothing.
...//some ok code before
...
...
onTextChange = (event) => {
const value = event.target.value;
let suggestions = [];
console.log(value); //Testing
console.log(value.lenght); //Testing -> doesn't work
if(value.lenght > 0){ //Nothing do cuz undefined
const regex = new RegExp(`^${value}`, 'i');
suggestions = this.items.sort().filter(v => regex.test(v));
console.log("Test!");//Testing
}
this.setState(() => ({suggestions, text: value}));
}
...
...//some ok code after
...
render() {
const { text } = this.state;
return (
<div >
<input value={text} onChange={this.onTextChange} type="text"/>
{this.renderSuggestion()}
</div>
);
}
Aucun commentaire:
Enregistrer un commentaire