没有显示在做什么npm启动react-app

时间:2017-03-06 07:04:17

标签: reactjs

我使用create-react-app创建了一个示例应用程序,在执行npm start时,它向我展示了默认的反应js页面。然后我将src中的app.js编辑为

import React from 'react';
import ReactDOM from 'react-dom';

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

但这显示了执行npm start的空白页面。我查了一下,index.html中已经有<div id="root">了。那为什么这会显示一个空白页?

我检查了控制台,它显示了2个错误:

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in.

Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in.

1 个答案:

答案 0 :(得分:0)

好的,我明白了。我在src中编辑App.js(因为它在默认的反应页面上被提到),而我需要编辑Index.js以运行该示例,或执行类似

的操作
import React from 'react';

const App = () =>{
    return (<h1>Hello, world!</h1>);
};

export default App;

这将在index.js中进行必要的更改。