Answers for "how to pass variables to makestyles"

1

pass props to style material ui

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>;
}
Posted by: Guest on July-31-2020
0

pass props to makestyles

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

//calling the function
const classes = useStyles(props)();
Posted by: Guest on July-26-2021
0

how to pass variables to 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>;
}
Posted by: Guest on July-26-2021

Code answers related to "how to pass variables to makestyles"

Code answers related to "Javascript"

Browse Popular Code Answers by Language