Skip to main content
If none of the existing widgets fit your use case, you can implement your own.
If you’re creating a custom InstantSearch widget because you didn’t find a built-in option for your use case, consider opening a feature request to describe what you’re trying to build.
Creating a widget takes three steps:
  • Create the MyWidgetViewModel, containing the business logic for your widget.
  • Create a MyWidgetView interface, describing the rendering of the widget data.
    • Implement your view in a MyWidgetViewImpl that you’ll use.
  • Create the Connections between your ViewModel and the other components:
    • Create a MyWidgetConnectionView to connect your ViewModel to its View.
    • If it uses the Searcher, create a MyWidgetConnectionSearcher.
    • If it uses the FilterState, create a MyWidgetConnectionFilterState.

Example

You’ll build a widget that displays the number of searches made since it was last clicked.
1

Create the view model

The ViewModel will be quite straightforward: it stores a sum that can be incremented or reseted to 0. It will use InstantSearch’s SubscriptionValue to allow subscribing to changes of the sum’s value.
Kotlin
2

Create the view interface

To interact with the data in our ViewModel, you need a view than can display a number, and handle clicks for resetting.
Kotlin
3

Implement the view

Implement a SumSearchesView: it should display the data received in setSum and trigger the onReset when clicked.
Kotlin
4

Create the connection view

To link the ViewModel and its View, define a connection to describe what should happen when connecting (subscribe to sum and set the reset callback) and when disconnecting (unsubscribe to sum and remove the callback).
Kotlin
5

Create the connection searcher

Because the widget needs to be aware of searches to count them, it needs to be connected to a Searcher.Subscribe to its response to call increment() on every new search response.
Kotlin
6

Create helper functions

To simplify usage of the widget, create two extension functions that connect the ViewModel to other components:
Kotlin

Final touches

You just created your first custom widget and you can now use it in your app like any other widget:
Kotlin
Last modified on July 22, 2026