-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathuse-search-suggestions.tsx
More file actions
48 lines (42 loc) · 1.38 KB
/
use-search-suggestions.tsx
File metadata and controls
48 lines (42 loc) · 1.38 KB
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
47
48
/*
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React from 'react'
import {useSearchSuggestions} from '@salesforce/commerce-sdk-react'
import Json from '../components/Json'
const searchQuery = 'shirt'
function UseSearchSuggestions() {
const {isLoading, error, data: result} = useSearchSuggestions({parameters: {q: searchQuery}})
if (isLoading) {
return (
<div>
<h1>Search Results</h1>
<h2 style={{background: 'aqua'}}>Loading...</h2>
</div>
)
}
if (error) {
return <h1 style={{color: 'red'}}>Something is wrong</h1>
}
return (
<>
<h1>Search Results</h1>
<h3>Search term: {searchQuery}</h3>
<ul>
{result?.productSuggestions?.products?.map(({productId, productName}) => {
return <li key={productId}>{productName}</li>
})}
</ul>
<hr />
<div>
<div>Returning data</div>
<Json data={{isLoading, error, result}} />
</div>
</>
)
}
UseSearchSuggestions.getTemplateName = () => 'UseSearchSuggestions'
export default UseSearchSuggestions