diff --git a/README.md b/README.md index 3e3e5eb..025616b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/react-minisearch.tsx b/src/react-minisearch.tsx index b4ba771..f5c1c20 100644 --- a/src/react-minisearch.tsx +++ b/src/react-minisearch.tsx @@ -22,7 +22,7 @@ export interface UseMiniSearch { miniSearch: MiniSearch } -export function useMiniSearch (documents: T[], options: Options): UseMiniSearch { +export function useMiniSearch (documents: readonly T[], options: Options): UseMiniSearch { const optionsRef = useRef(options) const miniSearchRef = useRef>(new MiniSearch(options)) const documentByIdRef = useRef<{ [key: string]: T }>({}) @@ -147,7 +147,7 @@ export function useMiniSearch (documents: T[], options: Options): Us useEffect(() => { utils.addAll(documents) - }, [utils]) // eslint-disable-line react-hooks/exhaustive-deps + }, []) // eslint-disable-line react-hooks/exhaustive-deps return { searchResults,