小编thi*_*ras的帖子

将 props 传递给 TS 中的 makeStyle

如何传递post.mainImagebackgroundImage风格。

这是我的代码;

import React from 'react';
import { Post } from '../interfaces';
import { makeStyles, createStyles, Theme } from '@material-ui/core/styles';
import Container from '@material-ui/core/Container';

type Props = {
  post: Post;
}

const useStyles = makeStyles<Theme, Props>((theme: Theme) =>
  createStyles({
    root: {
      maxWidth: '100%',
      backgroundImage: ({ post }) => post.mainImage
    },
    date: {
      margin: theme.spacing(1),
      marginLeft: theme.spacing(2)
    },
    heroimage: {
      maxWidth: '100%',
      height: 'auto',
      objectFit: 'cover'
    }
  })
);

export default function HeroPost({ post }: Props) { …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs material-ui next.js

5
推荐指数
1
解决办法
4911
查看次数

标签 统计

material-ui ×1

next.js ×1

reactjs ×1

typescript ×1