Search Using Filter Data React Native

--

If you need to search for your apps you can implement this method. To simplify, you can save data from the server to JSON and get and set data using AsyncStorage. You need once-call data.

Example Search Data React Native

Add function setSearchText and create state data for backup

constructor(){
super();
this.state ={
data : [],
dataBackup : [],
}
}setSearchText(event){
searchText = event.nativeEvent.text;
data = this.state.dataBackup;
searchText = searchText.trim().toLowerCase();
data = data.filter(l => {
return l.nama.toLowerCase().match( searchText );
});
this.setState({
data : data
});
}

don't forget to add a function when onchange, I’m using react element here.

render() {
return (
<View>
<SearchBar
lightTheme
onChange={this.setSearchText.bind(this)}
placeholder=’Type Here…’/>
)
}

I hope it’s helpful :D. Please comment below if you have questions.

--

--

Derry Berni Cahyady
Derry Berni Cahyady

Written by Derry Berni Cahyady

Data & Security Enthusiast | Software Engineer

Responses (1)