我想知道什么是与JSX标签内的变量混合的字符串值的最佳实践,我列出了我熟悉的选项:
render() {
const {totalCount} = this.state;
const totalCountStr = `Total count: ${totalCount}`;
return (
<div>
<h1>Total count: {totalCount}</h1> // 1
<h1>`Total count: ${totalCount}`</h1> // 2
<h1>{totalCountStr}</h1> // 3
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
最佳做法或用例以不同方式使用它们是什么?
谢谢!