Documentation
Latest
Latest
  • Reactify Search
  • Getting Started
  • Guides
    • Upgrade workflow
    • Upgrade v4 to v5
    • Liquid Theme
    • SSR
  • Release Notes
  • Troubleshooting
    • Categorising Issues
    • Common Issues
    • Debugger
    • CodeSandbox
    • Further Troubleshooting
  • Security Overview
  • Components
    • Component Basics
    • ReactifySearchProvider
    • Sensors
    • Search
    • SortBy
    • ClearAll
    • FiltersSelected
    • Filters
    • Filter
    • Results
    • Stats
    • Suggestions
    • CustomComponent
  • Hooks
    • useSearch
    • useSortBy
    • useFilters
    • useResults
  • Classes
    • ReactifySearchLiquidFactory
Powered by GitBook
On this page
  • Purpose
  • Usage
  • Props

Was this helpful?

  1. Components

Search

PreviousSensorsNextSortBy

Last updated 2 years ago

Was this helpful?

Purpose

The Search component is a wrapper for the , it provides a simple way to access and update the search terms while also handling special logic such as redirects.

Usage

import React from "react";
import { Search } from "@usereactify/search";

import { ExampleSearch } from "./ExampleSearch";

export const Component: React.FC = () => {
  return (
    <Search
      render={ExampleSearch}
    />
  );
};
import React from "react";
import { SearchProps } from "@usereactify/search";

export type ExampleSearchProps = React.ComponentProps<
  NonNullable<SearchProps["render"]>
>;

export const ExampleSearch: React.FC<ExampleSearchProps> = (props) => {
  const handleFormSubmit = React.useCallback(
    (event: React.FormEvent<HTMLFormElement>) => {
      event.preventDefault();
      props.submitSearchTerm();
    },
    [props.submitSearchTerm]
  );

  const handleInputChange = React.useCallback(
    (event: React.ChangeEvent<HTMLInputElement>) => {
      props.setSearchTerm(event.target.value);
    },
    [props.setSearchTerm]
  );

  return (
    <form onSubmit={handleFormSubmit}>
      <input
        type="search"
        placeholder="Search products..."
        value={props.searchTerm}
        onChange={handleInputChange}
      />
    </form>
  );
};

Props

type SearchProps = {
  /** Render method */
  render?: React.FC<ReturnType<typeof useSearch>>;
};
useSearch hook