-1

I have this in my jsx, # is used to stop the link if user click on the a tag.

<a target={obj.handlerName === 'detail' ? `_blank` : ''} href={obj.handlerName === 'detail' ? `/products/${id}` : '#'} >{obj.name}</a>

but I will have the extra # if the handlerName is not equal to 'detail'

Any clue how to get rid of that?

Alan Jenshen
  • 3,159
  • 9
  • 22
  • 35

1 Answers1

0

What about using the includes() method?

<a target={obj.handlerName.includes('detail') ? `_blank` : ''} href={obj.handlerName === 'detail' ? `/products/${id}` : '#'} >{obj.name}</a>

Here's some useful reference:

https://www.w3schools.com/jsref/jsref_includes.asp https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/includes