How to use an ejs variable inside a react render function?

柔情痞子 提交于 2019-12-06 07:43:00

I faced the same problem but with a index.html file, filled by a React component, and resolved it like this:

In index.html

<script>
    window.abcd = '<%- abcd %>';
</script>

In your react component

render: function(){
    return(
       <div>
            <p> {window.abcd} </p>
       </div>
    );
}

This worked perfectly for me, if someone has a cleaner proposition, i'm in!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!