彩虹一號
彩虹一號

Reputation: 43

UseState onclick nothing happen

I make a button to control the menu but I click the button and then nothing happen.There aren't run out any error msg.

const [display, changeDisplay] = useState('none')
  const [Icon, setIcon] = useState(<HamburgerIcon />)
  function Close() {
    return (
      <Box as='button' onClick={() => changeDisplay('none')}><CloseIcon /></Box>
    )
  }
<Box
            as="button"
            aria-label="Open Menu"
            position="relative"
            onClick={() => { changeDisplay('flex'); setIcon(<Close />) }}
            display={{ base: 'inline-block', md: 'none' }}
            margin={2}
          >
            {Icon}
          </Box>

Upvotes: 0

Views: 66

Answers (1)

Shafayet2368
Shafayet2368

Reputation: 226

replace the following code:

onClick={() => { changeDisplay('flex'); setIcon(<Close />) }}

with:

onClick={() => {changeDisplay('flex'); setIcon(Close())}}

Upvotes: 1

Related Questions