jsx-eslint/eslint-plugin-react

Rule proposal: ssr-friendly

Open

#2,057 创建于 2018年11月26日

在 GitHub 查看
 (21 评论) (23 反应) (0 负责人)JavaScript (2,797 fork)batch import
acceptedhelp wantednew rule

仓库指标

Star
 (8,630 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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

贡献者指南