2017-04-20 23 views
0

我的React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined.創建可以在JS類中重用的方法/函數。

我想有一個類中的公共方法,因爲我想重新使用該功能在其他方法錯誤,有什麼錯我下面的代碼?

componentDidMount() { 
    this.getCurrentMonthData('2017-10-1', '2017-12-1'); 
} 
getCurrentMonthData = (from, to) => { 
    //do something 
} 
OtherFunc =() => { 
    this.getCurrentMonthData('2017-10-1', '2017-12-1'); 
} 
+0

這是在類的主體或構造? –

+0

您的渲染功能存在問題。要麼你沒有寫渲染功能,或者它沒有返回任何東西。 –

回答

0
import {Your_Component_Name} from '../components/xyz.js'; 

VS

import Your_Component_Name from '../components/xyz.js'; 

在我的情況下,第二個作品,而第一個導致錯誤。

嘗試像這樣導入你的組件。

相關問題