【发布时间】:2021-12-10 23:42:32
【问题描述】:
我有一个样式组件:
import {styled} from '@mui/material/styles';
export const MovieModalStyle = styled(Box)(({theme}) => ({
// ...
background: `url(${'https://image.tmdb.org/t/p/w780/' + movie.backdrop_path})`,
}));
我想将movie 对象传递给它,这样我就可以使用backdrop_path 属性:
<MovieModalStyle movie={movie} />
在主题旁边引用电影道具返回错误:
styled(Box)(({theme, movie}) => ({
// Error: Property 'movie' does not exist on type
// IntrinsicAttributes & SystemProps<Theme>
我已尝试使用 https://mui.com/system/styled 文档中的示例,但似乎无法正常工作。
【问题讨论】:
-
你能创建一个codesandbox吗?
-
这能回答你的问题吗? Material-UI v5 passing props to CSS theme
-
@NearHuscarl 不完全是。好像我有一些打字错误。
-
打字稿错误可以在this答案中修复,你不需要使用
OverridableComponent,没必要。
标签: reactjs typescript material-ui