Search

Search

useSearch

Parameters:

No.VariabletypeRequiredDescription
1.doctypestringName of the doctype
2.textstringQuery string
3.filtersFilter[]-optional parameter to filter the result
4.limitnumber-the number of results to return. Defaults to 20
5.debouncenumber-the number of milliseconds to wait before making the API call. Defaults to 250ms.
export const Search = () => {
 
  const [searchText, setSearchText] = useState('');
  const { result } = useSearch('Item', searchText);
 
  const handleSearchTextChange = (e) => {
    setSearchText(e.target.value);
  };
 
  const handleSuggestionClick = (suggestion) => {
    setSearchText(suggestion.title);
    // Perform additional action based on the selected suggestion
  };
 
  return (
    <div>
      <input
        type="text"
        value={searchText}
        onChange={handleSearchTextChange}
        placeholder="Search..."
      />
      {result.length > 0 && (
        <ul className="dropdown-menu">
          {result.map((item) => (
            <li key={item.id} onClick={() => handleSuggestionClick(item)}>
              {item.title}
            </li>
          ))}
        </ul>
      )}
    </div>
  );
};