'use client'
const App = () => {
const [isFScreen, setIsFScreen] = useState(false)
useEffect(() => {
const down = (e: KeyboardEvent) => {
if (e.key === "Escape"){
setIsFScreen(false)
}
}
document.addEventListener("keydown", down)
}, [])
return(
<div id="gameScreen">
<span onClick={() => {
setIsFScreen(!isFScreen)
document.getElementById("gameScreen")?.requestFullscreen()}}>
Full Screen
</span>
</div>
)}
When I press the ESC key once, it exits full screen but "setIsFScreen" does not become false. I have to press it twice to make it false. How can i solve this?
I was expecting the status to be false when it exited full screen.
2
Answers
just use the listen events for fulllscreen