Nathan McKenzie
Nathan McKenzie

Reputation: 71

How do I hide a React component on the second click when the component is already open?

On the first click of IconButton, the React component is shown and on the second click, I'd like to hide the component.

export default function EditorToolbar(props) {

  const [open, setOpen] = React.useState(false);
  const handleOpen = () => {
    setOpen(true);
  };
}


 <IconButton size='small' onClick={handleOpen} >

Upvotes: 0

Views: 341

Answers (1)

Sakshi
Sakshi

Reputation: 1548

export default function EditorToolbar(props) {

  const [open, setOpen] = React.useState(false);
  const handleOpen = () => {
    setOpen(!open);
  };
}

return(
 <IconButton size='small' onClick={handleOpen} >
{open?show your react component here:null}
)

Upvotes: 2

Related Questions