javascript - How to add <script> tag using ReactJS? -
i need declare javascript function described below:
render: function() { return ( <div> <somereactclass somefunction="myfunction"> <script> function myfunction(index, row) { return index; <<<< error in line } </script> </div> ); } but, not compile: "parse error: line 113: unexpected token return"
how can add tag using reactjs?
update
i'm trying use bootstrap-table detail view. function passed parameter grid , used render row's detail. also, see example's source code better understanding.
when try way you're saying, compiles, not work @ all:
this how looks (in example above):

this i'm getting <somereactclass somefunction={myfunction}>

inside jsx, {...} denotes javascript expression. return index; on own not valid expression.
you have explicitly create string {...} not interpreted jsx. template literals may easiest solution:
<script>{` function myfunction(index, row) { return index; } `}</script> however, have hard time coming reason why 1 want create <script> dynamically.
what should pass function directly component:
function myfunction(index, row) { return index; } var component = react.createelement({ render: function() { return ( <div> <somereactclass somefunction={myfunction} /> </div> ); } }); but it's hard tell without explaining trying achieve here.
Comments
Post a Comment