M
M
Michael R.2019-06-11 15:01:55
JavaScript
Michael R., 2019-06-11 15:01:55

Expression along with string literal (jsx)?

Greetings!
Available:

const name = "world";
const element = <h1 className={url}>Hello, world!</h1>;
ReactDOM.render(element, document.getElementById('root'));

How can you specify both a string literal and an expression at the same time? For example, what I would like to get: (of course, the expression does not work, because it is in a string literal). Of course, you can use the modification of the expression even before embedding in jsx, but I would like to be able to be described above ...<h1 className="class_{url}">Hello, world!</h1>
const name = "world";
const nameModified = `class_${name}`;
const element = <h1 className={url}>Hello, world!</h1>;

How to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-06-11
@Mike_Ro

<h1 className={`class_${url}`}>Hello, world!</h1>
<h1 className={'class_' + url}>Hello, world!</h1>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question