jsx-eslint/eslint-plugin-react

Rule proposal: ssr-friendly

オープン

#2,057 opened on 2018/11/26

 (21 件のコメント) (23 件のリアクション) (0 人の担当者)JavaScript (2,731 件のフォーク)batch import
acceptedhelp wantednew rule

Repository metrics

Stars
 (9,293 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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

コントリビューターガイド