2017-01-20 8 views
8

Reactクラスを書くための推奨方法としてReact ES6に行っています。私はクローム55に次のエラーを取得していますChromeを使用したEcmascript6クラスの問題に反応する

import React from 'react'; 


class Dashboard extends React.Component { 
    render() { 
    return <h1>Hello, Don Trump</h1> 
    } 
} 

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

require('../node_modules/font-awesome/css/font-awesome.css'); 
require('../node_modules/bootstrap/dist/css/bootstrap.css'); 

require('jquery'); 
require('bootstrap'); 

import Dashboard from './components/Dashboard/Dashboard'; 

ReactDOM.render(
    <Dashboard/>, 
    document.getElementById('react-container') 
); 

そしてES6の私のコンポーネント:私は簡単な例から始めている

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. 
    at invariant (VM1093 bundle.js:9069) 
    at ReactCompositeComponentWrapper.instantiateReactComponent [as _instantiateReactComponent] (VM1093 bundle.js:23166) 
    at ReactCompositeComponentWrapper.performInitialMount (VM1093 bundle.js:23589) 
    at ReactCompositeComponentWrapper.mountComponent (VM1093 bundle.js:23480) 
    at Object.mountComponent (VM1093 bundle.js:16018) 
    at mountComponentIntoNode (VM1093 bundle.js:28717) 
    at ReactReconcileTransaction.perform (VM1093 bundle.js:17017) 
    at batchedMountComponentIntoNode (VM1093 bundle.js:28739) 
    at ReactDefaultBatchingStrategyTransaction.perform (VM1093 bundle.js:17017) 
    at Object.batchedUpdates (VM1093 bundle.js:26233) 

私が考えています何かシンプルな私は行方不明です。ヘルプがappreacited。

+0

ダッシュボードコンポーネント –

答えて

15

エラーメッセージはそれが正しいかもしれません:

あなたはおそらくそれがで定義されていたファイルからコンポーネントをエクスポートするのを忘れ

エクスポート以下のようなあなたのDashboardコンポーネント:。

import React from 'react'; 

class Dashboard extends React.Component { 
    render() { 
    return <h1>Hello</h1> 
    } 
} 

export default Dashboard; 
+2

Huhに「エクスポートのデフォルト」を追加する必要があります。非常に基本的な行方不明...ありがとう.... – Mendes

4

追加

輸出デフォルトのダッシュボードコンポーネントの終わりに

。 だから、新しいコードは、クラスをエクスポートする必要が

class Dashboard extends React.Component { 
    render() { 
    return <h1>Hello, Don Trump</h1> 
    } 
} 
export default Dashboard; 
1

になります。実際にエクスポートと宣言を同時に行うことができます

import React from 'react'; 

export default class Dashboard extends React.Component { 
    render() { 
    return <h1>Hello</h1> 
    } 
} 
関連する問題