-
- Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Description
In order to be SSR compliant, you can only access browser globals such as window
, document
and so on, inside of componentDidMount
, componentDidUpdate
and componentWillUnmount
A rule could be created to avoid the use of unguarded browser globals in other lifecycle methods.
Example of a guard:
if (typeof window !== 'undefined') { // I can use browser globals in here }
Use of browser globals are allowed when:
- used in a guard
- used in
componentDidMount
,componentDidUpdate
andcomponentWillUnmount
- used in
useEffect
oruseLayoutEffect
- used in an event handler
Haroenv, thiagodebastos, ZebraFlesh, sidharthachatterjee, cbovis and 18 more