Home > database >  Logical && Parsing error: Unexpected token, expected
Logical && Parsing error: Unexpected token, expected

Time:08-26

I am new to React and I am getting errors on the logical &&

export default function Index({children}) {
  const [isOpen, setIsOpen] = useState(true)
  return (
    {isOpen && true}
  )

The error reads

Parsing error: Unexpected token, expected ","

For demonstration purpose, I have replaced my div with true

CodePudding user response:

It thinks you're returning an object:

return ({
    isOpen && true
})

It expects , or : after isOpen.

You don't need the brackets:

return isOpen;
  • Related