Function useSort

  • Preact hook that import sort state to the component.

    Parameters

    Returns { activeSort: undefined | string; setSort: (sortId: string) => void }

    • activeSort: undefined | string

      Active sort

    • setSort: (sortId: string) => void

      Set sort function

    import { useSort } from '@nosto/preact'
    import { sortOptions } from '../config'

    export default () => {
    const { activeSort, setSort } = useSort(sortOptions)

    const handleSortChange = (event) => {
    setSort(event.target.value)
    }

    return (
    <div>
    <select
    value={activeSort}
    onChange={e => setSort(e.target.value)}
    >
    {sortOptions.map(option => (
    <option key={option.id} value={option.id}>
    {option.value.name}
    </option>
    ))}
    </select>
    </div>
    )
    }