简体   繁体   中英

Why ReactJS ReactDom.render() doesn't render HTML tags?

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">

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM