代码之家  ›  专栏  ›  技术社区  ›  Michael Harley Pawan Maheshwari

Create React App上的情感js定义为“jsx”,但从未使用过

  •  0
  • Michael Harley Pawan Maheshwari  · 技术社区  · 6 年前

    所以我试着用 emotion-js 第一次被css道具功能吸引住了。

    在尝试文档所说的内容时,我收到了eslint的警告。

    我使用的脚本是这样的。

    import React from "react";
    //** @jsx jsx */
    import { jsx } from "@emotion/core";
    
    export const Component = () => {
        return (
            <div css={{color: red}}>
                This is a component
            </div>
        )
    }
    

    我使用的是VSCode,所以我可以看到这个导入被标记为never used。(透明色)

    The jsx import is transparent (Never used)

    请帮助您如何避免此eslint警告,或者至少让VSCode识别正在使用jsx。


    编辑:(添加引用)

    参考文献: https://emotion.sh/docs/css-prop#jsx-pragma


    编辑2:我试着添加 .eslintrc 像这样的文件

    {
      "parser": "@typescript-eslint/parser",
      "plugins": ["@typescript-eslint"],
      "extends": ["plugin:@typescript-eslint/recommended"],
      "rules": {
        "@typescript-eslint/no-unused-vars": [
          2,
          { "vars": "all", "args": "all", "varsIgnorePattern": "^jsx$" }
        ]
      }
    }
    
    

    0 回复  |  直到 6 年前