LoginSignup
1
1

More than 1 year has passed since last update.

'React' must be in scope when using JSX react/react-in-jsx-scope と怒られた時の対応事情

Last updated at Posted at 2022-11-19

時間がない人用

.eslintrc.cjs
  extends: ['plugin:react/jsx-runtime'],

以前の情報

React は 17 以降に the new JSX transform というものが存在する。

ところが、この時に eslint からひたすら怒られた事はないだろうか。

error  'React' must be in scope when using JSX  react/react-in-jsx-scope

この対策、従来だと eslint の設定をいじるものが多かった。
いじるのは以下の二つ。

.eslintrc.cjs
 'rules': {
    'react/jsx-uses-react': 'off',
    'react/react-in-jsx-scope': 'off'
}

今の eslint-plugin-react

これは最近の eslint-plugin-react で修正が加えられている。

If you are using the new JSX transform from React 17, you should disable this rule by extending react/jsx-runtime in your eslint config (add "plugin:react/jsx-runtime" to "extends").

なので、お手元の eslintrcextends を一行追加することで対応できる。

.eslintrc.cjs
  extends: ['plugin:react/jsx-runtime'],
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1