How to concatenate variables and strings in React?

Spread the love

Sometimes, we want to concatenate variables and strings in React.

In this article, we’ll look at how to concatenate variables and strings in React.

How to concatenate variables and strings in React?

To concatenate variables and strings in React, we put the expression in braces.

For instance, we write

<button className={`tab__btn first ${props.state}`}>{props.text}</button>;

to set the className to a template string that has the props.state value interpolated into it.

Conclusion

To concatenate variables and strings in React, we put the expression in braces.

Leave a Reply

Your email address will not be published. Required fields are marked *