I have two strings which I want to concatenate using template literals. Second one is optional and I want to put it after comma (if exist). I know I can do something like this (but it doesn't look proper to me):
<div> {a} {b ? `, ${b}` : ''} </div> You can incapsulate logic to filter empty and joining into the component member (or util function), i.e.:
const concatNotEmptyBy = (separator) => (...args) => args .filter(n => n) // filter empty .join(separator); and next call it in your component:
<div> {concatNotEmptyBy(', ')(a, b)} </div> however, if it's only 1 place and only 2 variables then your original way is totally ok.
[a, b].filter(i => i).join(", ")- if you don't insist about literals