Develop ultra fast with Prismane 🎉

useSearch

useSearch hook provides a simple way to search through different types of data.

Import

import { useSearch } from "@prismane/core/hooks";

Usage

function Demo() {
  const { query, setQuery, filtered } = useSearch([
    "apple",
    "banana",
    "cherry",
    "date",
    "fig",
  ]);

  return (
    <Flex direction="column" gap={fr(4)} w={fr(96)}>
      <TextField
        placeholder="Search..."
        value={query}
        onChange={(e: any) => setQuery(e.target.value)}
      />
      <List>
        {filtered.map((item, index) => (
          <List.Item key={index}>{item}</List.Item>
        ))}
      </List>
    </Flex>
  );
}

API

Parameters

NameTypeDescriptionDefault
intialDataany[]The data that will be searched.-

Return Value

NameTypeDescription
querystringThe query that is searched through the data.
setQuery(query: string) => voidThe function that sets the new query by which the hook will search.
filteredany[]The searched data.