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

SortBy

PreviousSearchNextClearAll

Last updated 6 months ago

Was this helpful?

Purpose

The SortBy component is a wrapper for the , it provides a simple way to access and render the sort options.

Usage

If a render method is not provided the built-in component for sorting will be rendered.

See the useSortBy page for more usage details.

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

import { ExampleSortby } from "./ExampleSortBy";

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

export type ExampleSortByProps = React.ComponentProps<
  NonNullable<SortByProps["render"]>
>;

export const ExampleSortBy: React.FC<ExampleSortByProps> = (props) => {
  return (
    <select
      className="rs__sortby__select"
      value={props.sortOption?.handle}
      onChange={(event) => props.setSortOption(event.target.value)}
    >
      {props.sortOptions.map((sortOption) => (
        <option
          key={sortOption.handle}
          className="rs__sortby__option"
          value={sortOption.handle}
        >
          {sortOption.name}
        </option>
      ))}
    </select>
  );
};

Props

type SortByProps = {
  /** Render method called once for all sort options */
  render?: React.FC<ReturnType<typeof useSortBy>>;
};
useSortBy hook