I have a component with customButton for PWA:
const PWA = () => {
const [supportsPWA, setSupportsPWA] = useState(false)
const [deferredPrompt, setDeferredPrompt] = useState(null)
useEffect(() => {
const handler = e => {
e.preventDefault()
setDeferredPrompt(e)
setSupportsPWA(true)
}
window.addEventListener('beforeinstallprompt', handler)
return () =>
window.removeEventListener('beforeinstallprompt', handler)
}, [])
return (
<>
{supportsPWA.toString()}
{console.log(supportsPWA)}
{supportsPWA && <div>test</div>}
</>
)
}
export default PWA
I have beforeinstallprompt which I change supportsPWA status from false to true. In render I have supportsPWA.toString() it's always false. Console log return me: false and next true, so if supportsPWA is true why React not render div test?
EDIT:
I found where is the problem. I render PWA component in another component: {showMobileMenu && (<PWA />)}. showMobileMenu I changing by button (from false to true ) and here is problem. When I remove showMobileMenu && ... and I have only <PWA /> then div test is rendering correctly. But I dont know how I can resolve it?