|
1 | 1 | # Building a Search Bar in React Native |
2 | 2 |
|
3 | | -This guide walks you through building a mobile search interface using React Native (Expo) and Typesense. You'll create a cross-platform book search application that works on both iOS and Android devices, demonstrating how to integrate Typesense into your React Native projects. With over 60% of web traffic now coming from mobile devices, building fast and responsive mobile apps isn't just nice to have, it's essential. Mobile users expect instant results and won't wait around for slow searches. That's why combining React Native's native performance with Typesense's lightning-fast search engine creates the perfect foundation for a mobile app that your users will love. |
| 3 | +This guide walks you through building a native mobile search interface using React Native (Expo) and Typesense. |
| 4 | + |
| 5 | +You'll create a cross-platform book search application that works on both iOS and Android devices, demonstrating how to integrate Typesense into your React Native projects. |
| 6 | + |
| 7 | +Mobile users expect instant results and won't wait around for slow searches. That's why combining React Native's native performance with Typesense's lightning-fast search engine creates the perfect foundation for a mobile app search experience that your users will love. |
4 | 8 |
|
5 | 9 | ## What is Typesense? |
6 | 10 |
|
@@ -91,17 +95,17 @@ curl "http://localhost:8108/collections" \ |
91 | 95 | -H "Content-Type: application/json" \ |
92 | 96 | -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \ |
93 | 97 | -d '{ |
94 | | - "name": "books", |
95 | | - "fields": [ |
96 | | - {"name": "title", "type": "string", "facet": false}, |
97 | | - {"name": "authors", "type": "string[]", "facet": true}, |
98 | | - {"name": "publication_year", "type": "int32", "facet": true}, |
99 | | - {"name": "average_rating", "type": "float", "facet": true}, |
100 | | - {"name": "image_url", "type": "string", "facet": false}, |
101 | | - {"name": "ratings_count", "type": "int32", "facet": true} |
102 | | - ], |
103 | | - "default_sorting_field": "ratings_count" |
104 | | - }' |
| 98 | + "name": "books", |
| 99 | + "fields": [ |
| 100 | + {"name": "title", "type": "string", "facet": false}, |
| 101 | + {"name": "authors", "type": "string[]", "facet": true}, |
| 102 | + {"name": "publication_year", "type": "int32", "facet": true}, |
| 103 | + {"name": "average_rating", "type": "float", "facet": true}, |
| 104 | + {"name": "image_url", "type": "string", "facet": false}, |
| 105 | + {"name": "ratings_count", "type": "int32", "facet": true} |
| 106 | + ], |
| 107 | + "default_sorting_field": "ratings_count" |
| 108 | + }' |
105 | 109 | ``` |
106 | 110 |
|
107 | 111 | Now that the collection is set up, we can load the sample dataset. |
@@ -155,7 +159,7 @@ Let's go over the key dependencies: |
155 | 159 | - **typesense-instantsearch-adapter** - Connects InstantSearch with Typesense |
156 | 160 |
|
157 | 161 | :::tip Note |
158 | | -React Native can use `react-instantsearch-core` with the `typesense-instantsearch-adapter`, just like web frameworks. This gives you access to powerful InstantSearch hooks and widgets. Alternatively, you can make direct API calls to Typesense using the Fetch API for a lighter implementation. |
| 162 | +React Native can use `react-instantsearch-core` with the [`typesense-instantsearch-adapter`](https://github.com/typesense/typesense-instantsearch-adapter), just like web frameworks. This gives you access to powerful InstantSearch hooks and widgets. Alternatively, you can make direct API calls to Typesense using the Fetch API for a lighter implementation. |
159 | 163 | ::: |
160 | 164 |
|
161 | 165 | ## Project Structure |
@@ -227,9 +231,7 @@ Let's create the project structure step by step. After each step, we'll show you |
227 | 231 | Expo automatically loads environment variables starting with `EXPO_PUBLIC_` and makes them available to your app via `process.env`. |
228 | 232 | ::: |
229 | 233 |
|
230 | | - Using env variables is **NOT recommended** for production apps since they are bundled with the app and can be reverse engineered. If you must use a key on the client side, ensure it has restricted permissions (read-only only) and limited scope. |
231 | | - |
232 | | - For production, consider using a more secure method like a backend service behind an authentication layer to handle the API key. |
| 234 | + Using env variables is **NOT recommended** for production apps since they are bundled with the app. Instead, you want to generate a <RouterLink :to="`/${$site.themeConfig.typesenseLatestVersion}/api/api-keys.html#search-only-api-key`">search-only API key</RouterLink> and serve it to your app from a backend endpoint, along with your Typesense cluster endpoints. This way you can rotate your API keys and change your cluster endpoints at any point as needed. |
233 | 235 |
|
234 | 236 | 4. Create the types file: |
235 | 237 |
|
|
0 commit comments