I need to declare a javascript function as described below:
render: function() {
return (
<div>
<SomeReactClass somefunction="myFunction">
<script>
function myFunction(index, row) {
return index; <<<< error in this line
}
</script>
</div>
);
}
But, it does not compile: "Parse Error: Line 113: Unexpected token return"
How can I add tag using ReactJS?
I'm trying to use bootstrap-table detail view. The function is passed as parameter to the grid and it is used to render the row's detail. Also, see the example's source code for a better understanding.
When I try the way you're saying, it compiles, but does not work at all:
This is how it looks like (in example above):
This is what I'm getting with <SomeReactClass somefunction={myFunction}>
I know this is old, but i stumbled upon this recently and here is the best solution i found (i'm using it for browser polyfills, but it works for any code):
render: function() {
return (
<div>
<SomeReactClass somefunction="myFunction">
<script
dangerouslySetInnerHTML={{ __html:
`function myFunction(index, row) {return index;}`
}}
/>
</div>
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With