mardi 3 mars 2020

How solve a logical statement in Gatsby (react JS)?

I can't seem to wrap my head around a logical statement in react.js...

here is my code:

<li key={item.title}>
  {item.child_items 
    ? <Link 
      activeClassName="active"
      partiallyActive={true}
      aria-haspopup="true" 
      to={`/${item.slug}`}>{item.title}</Link> //reference line

    : <Link to={`/${item.slug}`}>{item.title}</Link>
  }
</li>

This part is working. What I am trying to accomplish is that if item.title is "home" then the reference line (commented above) would have be to={/}>{item.title}</Link>

I think i need a function here that renders {/} vs {/${item.slug}} or do I simply write in a nested if then statement?

Aucun commentaire:

Enregistrer un commentaire