如何去除属性值前后的块注释?

How to remove block comment before and after attribute value?

我用 Next.js 创建了简单的 SSR 页面。页面代码:

import fetch from 'isomorphic-unfetch'

function Index({ stars }) {
    return <div>Welcome to {stars}!</div>
}

Index.getInitialProps = async ({ req }) => {
    const res = await fetch('https://api.github.com/repos/zeit/next.js');
    const json = await res.json()
    return { stars: json.stargazers_count }
};

export default Index

如何去掉属性值前后的块注释?

<div>Welcome to <!-- -->43671<!-- -->!</div>

每个属性都应该有自己的块。
第一个解
您可以将属性添加到任何标签(<span><i> 和 e.t.c)。

<div>Welcome to <span>{stars}</span>!</div>

第二种解法
您可以在父标签中连接字符串。

<div>{'Welcome to '+stars+'!'}</div>