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):

enter image description here

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

enter image description here

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

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -