I'm trying to make a code work from https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Add_to_home_screen but I'm having a problem on my React.
I make a function called AddToHome
// Code to handle install prompt on desktop
export const addToHome = () => {
let deferredPrompt
const addBtn = document.querySelector('.add-button')
addBtn.style.display = 'none'
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault()
// Stash the event so it can be triggered later.
deferredPrompt = e
// Update UI to notify the user they can add to home screen
addBtn.style.display = 'block'
addBtn.addEventListener('click', () => {
// hide our user interface that shows our A2HS button
addBtn.style.display = 'none'
// Show the prompt
deferredPrompt.prompt()
// Wait for the user to respond to the prompt
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the A2HS prompt')
} else {
console.log('User dismissed the A2HS prompt')
}
deferredPrompt = null
})
})
})
}
and I'm importing it to my JS file
const handleClick = () => {
addToHome()
}
and calling it in a div
<button
onClick={handleClick}
style={{ position: 'absolute', top: '1px', left: '1px' }}
>
Add to home
</button>
I'm getting an error
I want to achieve what's in the code for me to have a pop up when I click the button when want to install my PWA on my desktop. 
