Inside JSX {...} stands for JavaScript expression. return index; per se is not a valid expression.
You must explicitly create a string so that {...} not interpreted by JSX. Template literals may be the easiest solution:
<script>{` function myFunction(index, row) { return index; } `}</script>
However, itβs hard for me to find the reason why you would like to dynamically create <script> .
What you should probably do is pass the function directly to the component:
function myFunction(index, row) { return index; } var Component = React.createElement({ render: function() { return ( <div> <SomeReactClass somefunction={myFunction} /> </div> ); } });
But itβs hard to say if you donβt explain what you are really trying to achieve here.
Felix kling
source share