reactjs - How to pass variable to react component -
for example, create react component this
var hellomessage = react.createclass({ render: function() { return <div>hello {this.props.name}</div>; } }); reactdom.render(<hellomessage name="john" />, mountnode);
so can pass message variable server? this
reactdom.render(<hellomessage name="{{ message }}" />, mountnode);
what you're trying should work. can instantiate javascript variable showed, have reactdom.render
call rendered in view server-side. no need render react component server-side, have render
call rendered on page.
for example, in javascript file, have component (hellomessage
) showed.
then, render second snippet of code (server-side) on page:
<script type="text/javascript"> reactdom.render(<hellomessage name="{{ message }}" />, mountnode); </script>
Comments
Post a Comment