Gatsby/React useEffect hook versus "typeof window"

Viewed 484

Can the useEffect() hook perform the same function as typeof window !== 'undefined';, whereby determining the availability of a browser window?

1 Answers

useEffect hook triggers initially after the component output has been rendered to the DOM. Therefore it is not exclusive to check the availability of the window because it may not be defined yet. You should check for the window regardless if you use useEffect or not.

You can check for further information about useEffect hook in React's documentation.

Related