【问题标题】:material UI styeled components how to apply style材质 UI 样式的组件如何应用样式
【发布时间】:2020-09-13 13:47:57
【问题描述】:

Styled with styled = 使用 MaterialUI 的组件
LoginTextField 中出现以下错误。
不知道怎么解决。

错误消息
[ts] 类型'{宽度:数字; }' 缺少来自类型 'Pick & Partial<...>、“label” | 的以下属性... 283 更多... | "width">': style, ref, className, onFocus 等 7 个。 [2740]

环境
打字稿,
React.js(钩子),
材质用户界面,
样式化组件,

// styleButton.tsx
import { Button,TextField } from "@material-ui/core";
import styled from "styled-components";

export const LoginTextField = styled(TextField)<{ width: number }>`
  width: ${(props) => props.width};
`
// index.tsx
import React, { FC, useState } from "react";
import styled from "styled-components";
import { LoginTextField } from "../components/styleButton"

export const Login: FC = () => {

return (
<LoginTextField width={600}></ LoginTextField>
)

【问题讨论】:

    标签: reactjs typescript material-ui material-design styled-components


    【解决方案1】:

    换成 styleButton.tsx 试试这个

    import { Button, TextField, TextFieldProps } from "@material-ui/core";
    import styled from "styled-components";
    
    //type aliases 
    type StyledTextFieldProps = TextFieldProps && { width: number };
    
    export const LoginTextField = styled(TextField)`
       width: ${(props: StyledTextFieldProps) => props.width} 
    ` as React.ComponentType<StyledTextFieldProps>;
    

    【讨论】:

    • 谢谢你。我在上面试过但不能。 erromessage ``` ts] 'number' 仅指一种类型,但在这里用作值。 [2693] 类型“TextFieldProps”中不存在属性“宽度”。 “StandardTextFieldProps”类型中不存在属性“宽度”。 [2339]```
    猜你喜欢
    • 2018-10-08
    • 1970-01-01
    • 2022-07-19
    • 2020-05-20
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 2019-10-09
    • 1970-01-01
    相关资源
    最近更新 更多