2017-03-06 50 views
0

我做了一個使用create-react-app的示例應用程序,並且在做npm start時,它向我展示了默認的反應js頁面。然後我編輯裏面的src app.js到沒有顯示在做npm開始反應-app

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. 

回答

0

好吧,我知道了。我編輯App.js內SRC(因爲它是在默認情況下提到的反應頁),而我需要編輯Index.js對於例如運行,或者做類似

import React from 'react'; 

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

export default App; 

,這將進行必要的更改在index.js中。

相關問題