“Cara meneruskan variabel ke Makestyles” Kode Jawaban

lulus alat peraga untuk gaya ui material

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import {Theme} from '@material-ui/core';

export interface StyleProps {
    height: number;
}

const useStyles = makeStyles<Theme, StyleProps>(theme => ({
  root: {
    background: 'green',
    height: ({height}) => height,
  },
}));

export default function Hook() {

  const props = {
    height: 48
  }

  const classes = useStyles(props);
  return <Button className={classes.root}>Styled with Hook API</Button>;
}
Cautious Coyote

lulus alat peraga ke Makestyles

const useStyles = props => makeStyles( theme => ({
    div: {
        width: theme.spacing(props.units || 0)  
    }
}));

//calling the function
const classes = useStyles(props)();
Graceful Gerenuk

Cara meneruskan variabel ke Makestyles

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import {Theme} from '@material-ui/core';

const useStyles = makeStyles(theme => ({
  root: {
    background: ({color})=> color,
  },
}));

export default function Hook() {
  const props = {
    color: "#1D3874"
  }
  const classes = useStyles(props);
  return <Button className={classes.root}>Styled with Hook API</Button>;
}
Silly Shrike

Jawaban yang mirip dengan “Cara meneruskan variabel ke Makestyles”

Pertanyaan yang mirip dengan “Cara meneruskan variabel ke Makestyles”

Lebih banyak jawaban terkait untuk “Cara meneruskan variabel ke Makestyles” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya