Zyg*_*tas 13 typescript reactjs material-ui styled-components
styled将 MUI 与 typescript 一起使用,并且也想从 MUI 中使用。当将组件属性传递给样式组件时,我从下面的打字稿沙箱中收到错误,也许有人知道解决方法。
https://codesandbox.io/s/material-demo-forked-lxdrj?file=/demo.tsx
您必须手动添加“组件”道具。
来自https://mui.com/material-ui/guides/typescript/#complications-with-the-component-prop
import React from "react";
import type { TypographyProps } from "@material-ui/core";
import { styled } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
type MyT = React.ComponentType<TypographyProps<"span", { component: "span" }>>;
const MyTypography: MyT = styled(Typography)({
background: "linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)",
border: 0,
borderRadius: 3,
boxShadow: "0 3px 5px 2px rgba(255, 105, 135, .3)",
color: "white",
height: 48,
padding: "0 30px"
});
export default function StyledComponents() {
return (
<MyTypography component="span">Styled with styled-components API</MyTypography>
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5960 次 |
| 最近记录: |