Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

reactjs - 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} >
question from:https://stackoverflow.com/questions/65848126/how-do-i-hide-a-react-component-on-the-second-click-when-the-component-is-alread

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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}
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...