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

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
  • 2
    {visibleMenu[name] && dropdownItem && dropdownItem.map ... } – HMR Mar 12 '20 at 18:51
  • 2
    Are you sure you want to create a new list for each item inside of `dropdownItem`? – goto Mar 12 '20 at 18:52
  • Does this answer your question? [if-else statement inside jsx: ReactJS](https://stackoverflow.com/questions/44046037/if-else-statement-inside-jsx-reactjs) – Emile Bergeron Mar 12 '20 at 19:03

1 Answers1

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>
azium
  • 20,056
  • 7
  • 57
  • 79