I need to add multilines conditionally in an ES6 Template Literal based on some conditions
and have extra indentations deleted on every line.
Code:
const reactComponentJSX = `
${condition1? '<Menu/>' : ''}
${condition2? '<p>Welcome to my app</p>' : ''}
${condition3? '<Body/>' : ''}
${condition4? '<h1>Good bye</h1>' : ''}
`;
Actual Output:
Let's assume condition1 and condition4 are false so following JSX would be printed.
// unnecessary new line
// unnecessary new line
<p>Welcome to my app</p>
// unnecessary new line
<h1>Good bye</h1>
Notice the unnecessary indents in each non empty line.
Expected Output:
Show lines without indentation and not print new line with false condition.
<p>Welcome to my app</p>
<h1>Good bye</h1>
Note: I am writing template for a JSX file. So, you can consider the problem statement as conditional writing JSX tags in render function, conditionally importing libraries in the JSX file, e.t.c.