react-native-searchbox provides declarative props to query Elasticsearch, and bind UI components with different types of search queries. As the name suggests, it provides a default UI component for searchbox.

Installation

To install react-native-searchbox, you can use npm or yarn to get set as follows:

Using npm

npm install @appbaseio/react-native-searchbox

Using yarn

yarn add @appbaseio/react-native-searchbox

react-native-searchbox requires react-native-vector-icons as a peer dependency. Expo or create-react-native-app projects include react-native-vector-icons out of the box, so all you need to do is install @appbaseio/react-native-searchbox.

If your project is a standard React Native project created using react-native init (it should have an ios/android directory), then you have to install the react-native-vector-icons along with react-native-searchbox.

Simple usage

A simple example

The following example renders an autosuggestion search bar(search-component) with one custom component(result-component) to render the results. The result-component watches the search-component for input changes and updates its UI when the user selects a suggestion.

Basic Usage

This example demonstrates the usage of some of the props available with react-native-searchbox. Please go over here to check it out.

Controlled Usage

In this example we can see the usage of search-box component in a controlled way using the value and onChange props and also how to use the transformRequest prop to get in more context from an extrenal API. Please go over here to check it out.

Advanced Usage

In this example, we show the usage of an additional facet to display the search results with increased relevancy. Please go over here to check it out.

DistinctField Prop Usage

In this example, we have shown how to usage distinctField and distinctFieldConfig props to display distinct value documents based on the specified field. Please go over here to check it out.

Index Prop Usage

In this example, we can see the usage of the index prop in the author-search-component to explicitly specify an index to query against for the component. Please go over here to check it out.

TransformRequest Prop Usage

In this example, we show the usage of the transformRequest prop, which gives us the request object whenever a query gets triggered from the search-box component. It allows us to either modify the request being sent or create a side-effect based on this request. Please go over here to check it out.

You can check out the docs for API Reference over here.