Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

Search.tsx

27 lines712 Bytes

1import { createDebouncedValue } from '@tanstack/solid-pacer/debouncer'
2import { createSignal } from 'solid-js'
3import SearchResults from './SearchResults'
4import type { JSX } from 'solid-js'
5​
6export default function Search() {
7 const [query, setQuery] = createSignal('')
8 const [debouncedQuery] = createDebouncedValue(query, { wait: 300 })
9​
10 const handleOnInput: JSX.EventHandler<HTMLInputElement, InputEvent> = (
11 event,
12 ) => {
13 event.preventDefault()
14 setQuery(event.currentTarget.value)
15 }
16​
17 return (
18 <div>
19 <input
20 onInput={handleOnInput}
21 value={query()}
22 placeholder="Search products"
23 />
24 <SearchResults query={debouncedQuery()} />
25 </div>
26 )