Skip to content

Getting started

Terminal window
npm install react-native-search-box

Nothing to link, no provider. React 16.8 and React Native 0.60 or later. It is tested with React 19 on React Native Web and on Android (React Native 0.88, New Architecture); see Migration for what changed since 0.0.20.

Live demo, try it.Open full screen ↗
  1. Render <Search /> at the top of the screen.
  2. Keep the query in state with onChangeText.
  3. Reset it in onDelete and onCancel, or pass value.
example/demos/basic.tsx
import { useState } from 'react';
import { FlatList, StyleSheet, Text, View } from 'react-native';
import Search from 'react-native-search-box';
const CITIES =
'Amsterdam,Bangkok,Barcelona,Berlin,Buenos Aires,Cairo,Cape Town,Đà Nẵng,Dublin,Hà Nội,Helsinki,Istanbul,Jakarta,Kyoto,Lima,Lisbon,London,Madrid,Mexico City,Montreal,Nairobi,New York,Oslo,Paris,Prague,Rome,Sài Gòn,Seoul,Singapore,Sydney,Taipei,Tokyo,Vienna,Warsaw,Zurich'.split(
',',
);
/** Case and accents do not matter: "ha noi" finds "Hà Nội". */
const normalize = (text: string) =>
text
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.replace(/đ/gi, 'd')
.toLowerCase();
export default function Basic() {
const [query, setQuery] = useState('');
const results = CITIES.filter((city) => normalize(city).includes(normalize(query.trim())));
const reset = () => setQuery('');
return (
<View style={styles.screen}>
<Search
backgroundColor="#e5e5ea"
titleCancelColor="#007aff"
placeholder="City"
inputHeight={36}
inputBorderRadius={10}
searchIconCollapsedMargin={34}
searchIconExpandedMargin={14}
placeholderExpandedMargin={30}
inputStyle={styles.input}
onChangeText={setQuery}
onDelete={reset}
onCancel={reset}
/>
<FlatList
data={results}
keyExtractor={(city) => city}
keyboardShouldPersistTaps="handled"
renderItem={({ item }) => <Text style={styles.row}>{item}</Text>}
ListEmptyComponent={<Text style={styles.empty}>No city matches “{query}”.</Text>}
/>
</View>
);
}
const styles = StyleSheet.create({
screen: { flex: 1, backgroundColor: '#fff' },
input: { fontSize: 16, color: '#111' },
row: {
paddingVertical: 13,
marginLeft: 16,
fontSize: 16,
color: '#111',
borderBottomWidth: 1,
borderColor: '#eee',
},
empty: { padding: 32, textAlign: 'center', color: '#6b7280' },
});
Terminal window
git clone https://github.com/anhtuank7c/react-native-search-box
cd react-native-search-box
npm install
npm run example