简体   繁体   English

没有重载匹配这个调用 | Typescript + React + Material UI

[英]No overload matches this call | Typescript + React + Material UI

I'm getting started with TypeScript for React combined with Material UI and I'm getting stuck with my very first component.我开始使用 TypeScript for React 与 Material UI 相结合,我被我的第一个组件卡住了。

 // material import { Box } from '@material-ui/core'; // ---------------------------------------------------------------------- export default function Logo() { return ( <Box component="img" alt="logo" src="/static/brand/logo.svg" height={40} /> ); }

I am getting errors at alt and src: No overload matches this call.我在 alt 和 src 处收到错误:没有重载匹配此调用。 I have the feeling that this is related to some configuration of the repo, but I still don't know what.我感觉这与 repo 的某些配置有关,但我仍然不知道是什么。

Thanks in advance for the help:)在此先感谢您的帮助:)

It throws the no overload matches this call because the Box component doesn't have the props you are trying to pass.它抛出 no 重载匹配此调用,因为 Box 组件没有您尝试传递的道具。 alt and src altsrc

A better approach would be to use the <Box /> as a wrapper if you want to set the size of the image如果要设置图像的大小,更好的方法是使用<Box />作为包装器

import { Box } from "@material-ui/core";

export default function Logo() {
  return (
    <Box height={40}>
      <img
        alt="logo"
        src="/static/brand/logo.svg"
        style={{ height: "100%" }}
      />
    </Box>
  )
}

The Box component serves as a wrapper component for most of the CSS utility needs. Box 组件用作大多数 CSS 实用程序需求的包装器组件。

https://material-ui.com/components/box/ https://material-ui.com/components/box/

The component prop changes the component that it renders in the DOM ( <div> is by default), but it shouldn't be used as the component itself. component属性会更改它在 DOM 中呈现的组件(默认情况下为<div> ),但不应将其用作组件本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM