简体   繁体   中英

Using a CDN to load React

I have a simple React App that I'm trying to load through using a CDN vs NPM.

My options.html file:

<!DOCTYPE html>
<html>
  <head>
    <title>My Test Extension Options</title>
    <script src="https://fb...me/react-0.14.3.js"></script>
    <script src="https://fb...me/react-dom-0.14.2.js"></script>
  </head>

  <body>
    <div id="root"></div>
    <script src="index.js" type="text/babel"></script>
  </body>
</html>

index.js

import React, { Component } from 'react'
import ReactDOM from 'react-dom';

class App extends Component {
    render() {
        return (
            <div>Hello world</div>
        )
    }
}


ReactDOM.render(<App />, document.getElementById('root'))

When I load up options.html in a browser, nothing is showing up when I expected to see Hello world. I checked the debugger and no errors are coming up.

What am I doing wrong?

I believe :

There is no need of type="text/babel"

<script src="index.js" type="text/babel"></script>

so it should be

<script src="index.js" ></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