jsx-eslint/eslint-plugin-react

Rule proposal: ssr-friendly

Offen

#2.057 geöffnet am 26.11.2018

 (21 Kommentare) (23 Reaktionen) (0 zugewiesene Personen)JavaScript (2.731 Forks)batch import
acceptedhelp wantednew rule

Repository-Metriken

Stars
 (9.293 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

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 and componentWillUnmount
  • used in useEffect or useLayoutEffect
  • used in an event handler

Contributor Guide