css 我在网上搜了一下,上面写着如何制作可重用的组件,我有个疑问

yrdbyhpb  于 2023-04-13  发布在  其他
关注(0)|答案(2)|浏览(132)

我完全按照书上的输入了,但是上面说css没有定义,是因为react的内容改变了很多吗?还是有什么问题?

import React from "react";
   import styled from "styled-components";

   const StyledButton = styled.button`
       border: none;
       border-radius: 4px;
       font-size: 1rem;
       font-weight: bold;
       padding: 0.25rem 1rem;
       color: white;
       outline: none;
       cursor: pointer;

       background: #343a40;
       &:hover {
           background: #868e96;
       }

       ${(props) =>
           props.fullwidth &&
           css`
               padding-top: 0.75rem;
               padding-bottom: 0.75rem;
               width: 100%;
               font-size: 1.125rem;
            `}

       ${(props) =>
            props.cyan &&
            css`
                background: #3bc9db;
                &:hover {
                    background: #66d9e8;
                }
            `}
    `;

    const Button = (props) => <StyledButton {...props} />;

    export default Button;
[eslint]
src\components\common\button.js
  Line 21:9:  'css' is not defined  no-undef
  Line 30:9:  'css' is not defined  no-undef

Search for the keywords to learn more about each error.
ERROR in [eslint]
src\components\common\button.js
  Line 21:9:  'css' is not defined  no-undef
  Line 30:9:  'css' is not defined  no-undef

Search for the keywords to learn more about each error.

webpack compiled with 1 error

我删除了css的信,并查阅了文献,但我找不到答案。

nxowjjhe

nxowjjhe1#

您需要从styled-components包导入css,因此导入将如下所示:

import styled, { css } from "styled-components";
yh2wf1be

yh2wf1be2#

为什么要使用CSS?
你只要把它取下来就行了

相关问题