-1

I am trying to move the BUTTON component below by adding a style further up my screen but it does not seem to be responding.

import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import Button from '@material-ui/core/Button';
import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles((theme) => ({

downButton: {
marginLeft: 10,
bottom: 50
},
}));

function App() {
const style = useStyles();

  <Button
  style={useStyles.downButton}
  onClick={() => console.log('clicked')}
  color="default"
  startIcon={<ExpandMoreIcon/>}
  ></Button>

  }

How do I add style this button and move it?

2 Answers 2

1

You have to use style not useStyles when you call css in component:

import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import Button from '@material-ui/core/Button';
import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles((theme) => ({

downButton: {
marginLeft: 10,
bottom: 50
},
}));

function App() {
const style = useStyles();

  <Button
  className={style.downButton} //<-- here should be style, not useStyles
  onClick={() => console.log('clicked')}
  color="default"
  startIcon={<ExpandMoreIcon/>}
  ></Button>

  }
Sign up to request clarification or add additional context in comments.

3 Comments

I seem to get an error after chaning styles to style Error: The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.
@MoMiah try to replace style prop with className. I updated my answer
@MoMiah No problem. If you think the answer is correct, please, mark it as valid. Happy coding =)
1

You was almost there 😁

import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import Button from '@material-ui/core/Button';
import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles((theme) => ({

downButton: {
marginLeft: 10,
bottom: 50
},
}));

function App() {
const style = useStyles(); 

  <Button
  style={style.downButton} //THIS SHOULD BE style NOT useStyles
  onClick={() => console.log('clicked')}
  color="default"
  startIcon={<ExpandMoreIcon/>}
  ></Button>

  }

1 Comment

Error: The style prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.