-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathuse-dnt.tsx
More file actions
40 lines (36 loc) · 1.11 KB
/
use-dnt.tsx
File metadata and controls
40 lines (36 loc) · 1.11 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
/*
* 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, {useEffect, useState} from 'react'
import {useDNT} from '@salesforce/commerce-sdk-react'
const buttonStyle = {
backgroundColor: '#007bff',
color: 'white'
}
const UseDntHook = () => {
const [displayButton, setDisplayButton] = useState(false)
const {selectedDnt, updateDNT} = useDNT()
useEffect(() => {
if (selectedDnt === undefined) setDisplayButton(true)
}, [])
return displayButton ? (
<button
style={buttonStyle}
onClick={() => {
void (async () => {
await updateDNT(null)
})()
setDisplayButton(false)
}}
>
DNT cookie is not set, click this button to update DNT
</button>
) : (
<div>DNT cookie is successfully set</div>
)
}
UseDntHook.getTemplateName = () => 'UseDntHook'
export default UseDntHook