useSearch

useSearch(
        searchQuery: string | ISearchQuery,
        options?: SearchOptions,
        deps?: any[]): [`SpSearchResult` | null | undefined, `GetPageDispatch`]

Conduct search on SharePoint.

Examples

Basic search,

const [results, setPage] = useSearch("search text");

// load next page
setPage(2);

// load page with callback
setPage(3, () => alert("Page Loaded!"));

Advanced search,

const query = {
        Querytext: "*",
        RowLimit: 5,
        RowsPerPage: 5,
        SelectProperties: ["Title"]
};

// Using dependency list to react query property changes.
const [results, setPage] = useSearch(query, undefined, [query?.Querytext]);

Parameters

NameTypeDescriptionTracked for changes
searchQuerystring | ISearchQuerySearch query object or search textYes for string, No for ISearchQuery
options?SearchOptionsuseSearch hook optionsPartially
deps?DependencyListHook dependency list.Yes