-
Notifications
You must be signed in to change notification settings - Fork 0
/
WithObjects.tsx
46 lines (42 loc) · 1.07 KB
/
WithObjects.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { useState } from 'react'
import { FzfHighlight, useFzf } from 'react-fzf'
import { posts } from '../utils/data'
import { Example } from '../utils/Example'
export function WithObjects() {
const [query, setQuery] = useState('')
const { getFzfHighlightProps, results } = useFzf({
items: posts,
itemToString(item) {
return item.title
},
query,
})
return (
<Example
title="with objects"
header={
<label>
query:
<input type="text" placeholder="filter…" value={query} onChange={(event) => setQuery(event.target.value)} />
</label>
}
>
<Example.Input>
<ul>
{posts.map((post) => (
<li key={post.title}>{JSON.stringify(post)}</li>
))}
</ul>
</Example.Input>
<Example.Output>
<ul>
{results.map((item, index) => (
<li key={item.title}>
<FzfHighlight {...getFzfHighlightProps({ index, item })} />
</li>
))}
</ul>
</Example.Output>
</Example>
)
}