Active sort
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>
)
}
Preact hook that import sort state to the component.