Skip to content

meilisearch/meilisearch-react

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

Update README.md with proper link to getting_started/installation
56bfa21

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
April 12, 2022 19:11
May 29, 2023 17:12

Meilisearch-React

Meilisearch React

Meilisearch | Documentation | Discord | Roadmap | Website | FAQ

License

How to integrate a front-end search bar in your React application using Meilisearch

Meilisearch is an open-source search engine. Discover what Meilisearch is!

This repository describes the steps to integrate a relevant front-end search bar with a search-as-you-type experience!

Installation

To integrate a front-end search bar, you need to install two packages:

  • the open-source React InstantSearch library powered by Algolia that provides all the front-end tools you need to highly customize your search bar environment.
  • the Meilisearch client instant-meilisearch to establish the communication between your Meilisearch instance and the React InstantSearch library.
    Instead of reinventing the wheel, we have opted to reuse the InstantSearch library for our own front-end tooling. We will contribute upstream any improvements that may result from our adoption of InstantSearch.

Run:

yarn add react-instantsearch-dom @meilisearch/instant-meilisearch
# or
npm install react-instantsearch-dom @meilisearch/instant-meilisearch

NB: If you don't have any Meilisearch instance running and containing your data, you should take a look at this getting started page.

Getting Started

Thanks to the open-source React InstantSearch library, you can add these components to your application:

import React from 'react';
import { InstantSearch, SearchBox, Hits, Highlight } from 'react-instantsearch-dom';
import { instantMeiliSearch } from '@meilisearch/instant-meilisearch';

const searchClient = instantMeiliSearch(
  'https://ms-adf78ae33284-106.lon.meilisearch.io',
  'a63da4928426f12639e19d62886f621130f3fa9ff3c7534c5d179f0f51c4f303'
);

const App = () => (
  <InstantSearch
    indexName="steam-video-games"
    searchClient={searchClient}
  >
    <SearchBox />
    <Hits hitComponent={Hit} />
  </InstantSearch>
);

const Hit = ({ hit }) => <Highlight attribute="name" hit={hit} />;

export default App

🚀 For a full getting started example, please take a look at this CodeSandbox:

Edit MS + React-IS

💡 If you have never used React InstantSearch before, we recommend reading this getting started documentation.

Customization and Documentation


Meilisearch provides and maintains many SDKs and Integration tools like this one. We want to provide everyone with an amazing search experience for any kind of project. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the integration-guides repository.