Skip to content

Commit

Permalink
Clarify docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaong committed Jul 6, 2023
1 parent 1ddd285 commit 739263f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ yarn add react-minisearch

There are three main ways to use `react-minisearch`: the `useMiniSearch` hook, the `withMiniSearch` higher-order component, or the `WithMiniSearch` wrapper component.

All three way take the following arguments (or props for the wrapper component):

- The initial collection of documents to add to the index. Note: this is just
the initial collection, and mutating this argument won't cause reindexing.
To add or remove documents after initialization, use the functions
`add`/`addAll`/`remove`/`removeAll`/`discard`, etc.
- The `MiniSearch` configuration options

#### Using the useMiniSearch hook:

```jsx
Expand Down
4 changes: 2 additions & 2 deletions src/react-minisearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface UseMiniSearch<T = any> {
miniSearch: MiniSearch<T>
}

export function useMiniSearch<T = any> (documents: T[], options: Options<T>): UseMiniSearch<T> {
export function useMiniSearch<T = any> (documents: readonly T[], options: Options<T>): UseMiniSearch<T> {
const optionsRef = useRef(options)
const miniSearchRef = useRef<MiniSearch<T>>(new MiniSearch<T>(options))
const documentByIdRef = useRef<{ [key: string]: T }>({})
Expand Down Expand Up @@ -147,7 +147,7 @@ export function useMiniSearch<T = any> (documents: T[], options: Options<T>): Us

useEffect(() => {
utils.addAll(documents)
}, [utils]) // eslint-disable-line react-hooks/exhaustive-deps
}, []) // eslint-disable-line react-hooks/exhaustive-deps

return {
searchResults,
Expand Down

0 comments on commit 739263f

Please sign in to comment.