0

I want to hide this material UI button if user is logged in but cant do conditional rendering because it will mess up the whole display flex items so i just want to do display none, is it possible to do display none conditionally?

        <Button
      variant="contained"
      color="primary"
      size="large"
      style={{ paddingLeft: "50px", paddingRight: "50px" }}
      className={classes.primaryAction}
    >
      {content["login"]}
    </Button>
dev
  • 255
  • 1
  • 3
  • 15
  • Does this answer your question? [Correct way to handle conditional styling in React](https://stackoverflow.com/questions/35762351/correct-way-to-handle-conditional-styling-in-react) – Samball May 05 '22 at 07:28

2 Answers2

1

yes it is possible, but I belive you will hit the very same issue, it it dissapears, it will break your flex anyways, but you can try this.

   <Button
      variant="contained"
      color="primary"
      size="large"
      style={{ paddingLeft: "50px", paddingRight: "50px", display: isLoggedIn ? "none" : "block" }}
      className={classes.primaryAction}
    >
      {content["login"]}
    </Button>
Lukáš Gibo Vaic
  • 3,960
  • 1
  • 18
  • 30
0

The way to do it without affecting your flex items or so, is setting the display attribute as 'none' only when you want to hide it and nothing if you want it to be displayed:

<Button
  variant="contained"
  color="primary"
  size="large"
  sx={{ paddingLeft: "50px", paddingRight: "50px", display: isLoggedIn && 'none' }}
  className={classes.primaryAction}
>
    {content["login"]}
</Button>