当我使用jsx编译指示时,如何停止eslint抛出错误。
我正在使用airbnb配置,并尝试将"react/jsx-uses-react": 1,作为规则添加,但未起作用。
在使用airbnb时,我需要在扩展中包含plugin:react/recommended吗?
.eslintrc.js
extends: [
"airbnb",
"airbnb/hooks",
"plugin:react-redux/recommended",
"plugin:prettier/recommended",
"prettier/react",
],
settings: {
react: {
version: "detect",
},
},
plugins: ["emotion", "graphql", "prettier", "react-redux"],
rules: {
"emotion/jsx-import": "error",
"emotion/no-vanilla": "error",
"emotion/import-from-emotion": "error",
"emotion/styled-import": "error",
"react/jsx-filename-extension": [1, { extensions: [".js", ".jsx"] }],
"graphql/template-strings": [
`error`,
{
env: `relay`,
tagName: `graphql`,
},
],
},layout.js
/* ESLint: 'React' is defined but never used.(no-unused-vars) */
import React from "react"
import PropTypes from "prop-types"
import { useStaticQuery, graphql } from "gatsby"
/** @jsx jsx */
import { Global, css, jsx } from "@emotion/core"
import { ThemeProvider } from "emotion-theming"发布于 2021-06-28 20:22:00
我遇到了一个类似的问题,只导出一个样式的组件。我将其包装在<React.Fragment>中并将其导出。
之前:
import React from 'react';
import styled from '@emotion/styled';
export const LabelText = styled.span`
font-size: 0.75em;
font-weight: 500;
`;之后:
import React from 'react';
import styled from '@emotion/styled';
const StyledSpan = styled.span`
font-size: 0.75em;
font-weight: 500;
`;
export const LabelText = ({ children }) => (
<React.Fragment>
<StyledSpan>{children}</StyledSpan>
</React.Fragment>
);https://stackoverflow.com/questions/61827432
复制相似问题