-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathindex.tsx
More file actions
41 lines (36 loc) · 1.04 KB
/
index.tsx
File metadata and controls
41 lines (36 loc) · 1.04 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
/*
* Copyright (c) 2022, Salesforce, 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, {ReactElement} from 'react'
import Json from '../../Json'
import {useBasket} from '@salesforce/commerce-sdk-react'
export const UseBasket = ({basketId}: {basketId: string}): ReactElement | null => {
const {isLoading, error, data} = useBasket({parameters: {basketId}})
if (!basketId) {
return null
}
if (isLoading) {
return (
<div>
<h1>Basket</h1>
<h2 style={{background: 'aqua'}}>Loading...</h2>
</div>
)
}
if (error) {
return <h1 style={{color: 'red'}}>Something is wrong</h1>
}
return (
<>
{data && (
<>
<h2>useBasket</h2>
<Json data={{isLoading, error, data}} />
</>
)}
</>
)
}