0

Hi I'm trying to render the following with a condition, but I'm not getting it for some reason: Parsing error: Unexpected token, expected ","

in my {dropdownItem.map (item => (

<NavLi>
  <Link to={link}>{name}</Link>
  {visibleMenu[name] && dropdownItem &&
  (
    {dropdownItem.map(item=>(
      <ul>
        <li>
          {item}
        </li>
      </ul>
    ))
    }
  )
  }
</NavLi>

I don't know what's wrong with my structure

3
  • 2
    {visibleMenu[name] && dropdownItem && dropdownItem.map ... } Commented Mar 12, 2020 at 18:51
  • 2
    Are you sure you want to create a new list for each item inside of dropdownItem? Commented Mar 12, 2020 at 18:52
  • Does this answer your question? if-else statement inside jsx: ReactJS Commented Mar 12, 2020 at 19:03

1 Answer 1

1

You have extra curly braces in your JSX. Once you open up { to tell the JSX that you want to evaluate an expression you don't need to open another one.

<NavLi>
  <Link to={link}>{name}</Link>
  {visibleMenu[name] && dropdownItem &&
    dropdownItem.map(item => (
      <ul>
        <li>
          {item}
        </li>
      </ul>
    ))
  }
</NavLi>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.