I am trying to learn ReactJS and how Javascript code interacts with the components in ReactJS and am not able to get a simple example to work.
Given below is my index.js file:
class JsBasic extends React.Component{
render(){
return(
var hello = () => alert('hello')
hello()
);
}
}
ReactDOM.render(
<JsBasic/>
document.getElementById('root')
);
On doing a npm start, I get the following error:
./src/index.js
Syntax error: Unexpected token (53:6)
51 |
52 | return(
> 53 | var hello = () => alert('hello')
| ^
54 | hello()
55 | );
56 | }
Any help greatly appreciated.