snakesilk / react-fullscreen

Fullscreen helper component for React.
https://www.npmjs.com/package/react-full-screen
MIT License
280 stars 33 forks source link

.enter and .exit resets a variable's state #68

Closed raulbarriga closed 3 years ago

raulbarriga commented 3 years ago

When I call .enter or .exit the state of one of my variables is reset to its default state. Any idea how to stop this?

Update: I fixed this issue using a useRef and a. useEffect to watch the previous state of the variable and use that to update my variable accordingly.

I think the reason for the state resetting might be since I'm using React's createPortal for a modal image carousel on which I use this fullscreen package so it might not have been the package at all. When I console logged the variable upon entering the fullscreen api, its state was reset so I just added an if statement to signal out this condition and give me the expected result while also adding a state update after calling .enter() to update the variable based on the useRef's previous value that I needed to stay consistent and not reset.

pomle commented 3 years ago

@raulbarriga if this is still a problem, please supply example of code you are running and reopen.