Skip to content

Commit

Permalink
docs(renderer): add usage warning (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour authored Mar 1, 2021
1 parent 612b040 commit 2d10778
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/website/docs/creating-a-renderer.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
---
id: creating-a-renderer
title: Creating a Renderer
title: Creating a custom renderer
---

Learn how to build an autocomplete UI using React.
Learn how to build a full autocomplete UI from the ground up.

The [`autocomplete-js`](autocomplete-js) package includes everything you need to render a JavaScript autocomplete experience that you can bind to [your own framework](autocomplete-js#renderer). If you want to build a custom UI that differs from the `autocomplete-js` output, for example in [React](https://reactjs.org/docs/getting-started.html) or another front-end framework, the [`autocomplete-core`](createAutocomplete) package provides all the primitives to build it.

This guide shows how to leverage all the autocomplete capacities to build an accessible autocomplete, both for desktop and mobile, with React. You can find the final result in [this sandbox](https://codesandbox.io/s/github/algolia/autocomplete.js/tree/next/examples/react-renderer?file=/src/Autocomplete.tsx).

:::info You might not need a custom renderer

Building a custom renderer is an advanced pattern that leverages the [`autocomplete-core`](createAutocomplete) package to fully control the rendered experience. You shouldn't need to use it unless you've reached limitations with [`autocomplete-js`](autocomplete-js) and it's templating capabilities.

:::

## Importing the package

Begin by importing [`createAutocomplete`](createAutocomplete) from the [core package](createAutocomplete) and [`getAlgoliaHits`](getAlgoliaHits) from the [Algolia preset](getAlgoliaHits). The preset—[`autocomplete-preset-algolia`](autocomplete-js)—is a utility function to retrieve items from an Algolia index.
Expand Down Expand Up @@ -80,6 +86,7 @@ function Autocomplete() {
```

Note the following commented portions:

- (1) You can leverage a React state for the autocomplete component to re-render when the [Autocomplete state](state) changes.
- (2) You can listen to all Autocomplete state changes to synchronize them with the React state.
- (3) This example uses an Algolia index as a [source](sources).
Expand Down

0 comments on commit 2d10778

Please sign in to comment.