-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathuse-promotions.tsx
More file actions
47 lines (44 loc) · 1.28 KB
/
use-promotions.tsx
File metadata and controls
47 lines (44 loc) · 1.28 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
/*
* 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 {usePromotions} from '@salesforce/commerce-sdk-react'
import Json from '../components/Json'
function UsePromotions() {
const {
data: result,
isLoading,
error
} = usePromotions({parameters: {ids: '10offsuits,50%offorder'}})
if (isLoading) {
return (
<div>
<h1>Promotions</h1>
<h2 style={{background: 'aqua'}}>Loading...</h2>
</div>
)
}
if (error) {
return <h1 style={{color: 'red'}}>Something is wrong</h1>
}
return (
<>
<h1>Promotions:</h1>
{result?.data?.map(({id, name}) => {
return (
<div key={id} style={{marginBottom: '10px'}}>
<div>Name: {name}</div>
<div>id: {id}</div>
</div>
)
})}
<hr />
<h3>Returning data</h3>
<Json data={{isLoading, error, result}} />
</>
)
}
export default UsePromotions