Next.js Discord

Discord Forum

How can I use document within my component?

Unanswered
Jimdog posted this in #help-forum
Open in Discord
Avatar
JimdogOP
I've made a function called hidePopups which is being used within my html img tag within my component. The issue is, when I write it outside of a useEffect, I get document is not defined reference error. When I try use it within a useEffect, it's out of scope.

Do I need to make a seperate file and import it as a function or something?
Image
Image

1 Reply

Avatar
Ray
try
function hidePopups() {
  if (typeof window !== 'undefined') {
     let pops = .....
  }
}