Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
60
rated 0 times [  65] [ 5]  / answers: 1 / hits: 17151  / 7 Years ago, mon, march 6, 2017, 12:00:00

why this code below doesn't work?



ReactDOM.render( <h1>Hello</h1>, document.getElementById('root'));


but this code works.



var elem = React.createElement('h1',{},Hello);
ReactDOM.render( elem, document.getElementById('root'));


Coming back to react after long time..trying looking into the web.. didn't found it deprecated ? then why its not working?



Update: My browser console displays syntax error over here



 ReactDOM.render( <h1>Hello</h1>, document.getElementById('root'));


UPDATE: Thanks for the help everything worked by adding the following line



<script type=text/babel>

More From » reactjs

 Answers
5

It is working, may be you are doing some other mistake, check this:




<script src=https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js></script>
<script src=https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js></script>
<script src=https://unpkg.com/babel-standalone@6/babel.min.js></script>

<div id='root'/>

<script type=text/babel>
ReactDOM.render( <h1>Hello</h1>, document.getElementById('root'));
</script>




[#58666] Friday, March 3, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tobyl

Total Points: 598
Total Questions: 110
Total Answers: 114

Location: Vietnam
Member since Sat, Feb 12, 2022
2 Years ago
;