浏览器中的引用响应组件

时间:2018-05-25 22:24:29

标签: reactjs babeljs react-dom

出于简单的测试目的,我想创建一个React应用程序,通过babel在浏览器中呈现。所以我不使用反应启动器套件。

所以我有一个非常简单的页面如下;

 <script type="text/jsx" src="Link.react.js"></script>
    <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>

<body>
    <div id="root"></div>
    <script type="text/babel">    
    ReactDOM.render(<Link page="https://www.facebook.com" />, document.getElementById('root'));
    </script>
</body>

此处Link.react.js有一个反应组件,如下所示;

export default class Link extends React.Component {
// basic implementation
}

但是它没有呈现,并且给出了一大堆错误,比如

 Uncaught ReferenceError: exports is not defined
 React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

有没有办法实现这个目标?或者我应该使用react-scripts实用程序来首先编译它们?

0 个答案:

没有答案