Getting started
npm install react-native-search-boxNothing 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.
First box
Section titled “First box”- Render
<Search />at the top of the screen. - Keep the query in state with
onChangeText. - Reset it in
onDeleteandonCancel, or passvalue.
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' },});View on GitHub: example/demos/basic.tsx
Run the demos on a device
Section titled “Run the demos on a device”git clone https://github.com/anhtuank7c/react-native-search-boxcd react-native-search-boxnpm installnpm run example