最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - How to write JavaScript code inside html attributes in React JS - Stack Overflow

programmeradmin6浏览0评论
return(
  <div>
    <Loading loadingMessage="Running "{this.state.programName}" program"/>
  </div>
);

I know that above attribute loadingMessage value is syntactically wrong. But my need is, I need to get that programName from state and append to loadingMessage attribute value. How can I do this? Any help will be appreciated.

return(
  <div>
    <Loading loadingMessage="Running "{this.state.programName}" program"/>
  </div>
);

I know that above attribute loadingMessage value is syntactically wrong. But my need is, I need to get that programName from state and append to loadingMessage attribute value. How can I do this? Any help will be appreciated.

Share Improve this question edited Apr 19, 2016 at 0:11 Unheilig 16.3k193 gold badges70 silver badges101 bronze badges asked Apr 18, 2016 at 22:58 Chetan MotamarriChetan Motamarri 1,2442 gold badges12 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You can write javascript inside the curly brackets, just concatenate the string in there.

return (
    <div>
        <Loading
            loadingMessage={"Running " + this.state.programName + " program"}
        />
    </div>
);

or use a template literal:

<Loading loadingMessage={`Running ${this.state.programName} program`}/>
发布评论

评论列表(0)

  1. 暂无评论