in react 17 is not necessarily use
import React from 'react';
but if i don't have it, so eslint gave me error
'React' must be in scope when using JSX react/react-in-jsx-scope
any idea how modify .eslintrc.js
module.exports = {
parser: "babel-eslint",
env: {
browser: true,
node: true,
es6: true,
jest: true,
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:jsx-a11y/recommended"
],
plugins: [
"react",
"react-hooks",
"jsx-a11y",
],
rules: {
strict: 0,
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
},
settings: {
react: {
version: "detect"
}
}
}
for react 17?
Thank's a lot
Starting from React 17, JSX transform use special jsx function internally. You don't need to import it.
You no longer need to import React from "react" . Starting from the release 17 of React, JSX is automatically transformed without using React.
Without it, the transformed JSX code would fail in the browser as React needs to be in scope to create components through its createElement function.
To use JavaScript inside of JSX, you need to surround it with curly braces: {} . This is the same as when you added functions to attributes. To create React components, you'll need to convert the data to JSX elements. To do this, you'll map over the data and return a JSX element.
You need to add plugin:react/jsx-runtime
to extends
in the .eslintrc.js
file.
like is:
module.exports = {
extends: [
'plugin:react/recommended',
'airbnb',
'plugin:react/jsx-runtime',
]
}
Refer here
You can read about it in React docs.
If you are using
eslint-plugin-react
, thereact/jsx-uses-react
andreact/react-in-jsx-scope
rules are no longer necessary and can be turned off or removed.
{
// ...
"rules": {
// ...
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off"
}
}
react-in-jsx-scope
on github.To make it work, you should add those rules to your eslint
config, see Extending or replacing the default ESLint config for Create-React-App specifics, every framework should have related section in their docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With