2017-02-19 53 views
0

我想這個組件react-native-calendar錯誤:空不是一個對象

它總是給人錯誤null is not an object (evaluating this.state.date)

我試圖初始化狀態變量命名的狀態併爲它指定的日期值,但錯誤依然存在。

var Calendar = require('react-native-calendar-component'); 

export default class proj extends Component { 

constructor(props) { 
super(props); 
this.state = { 
date: new Date() 
}; 
} 

render() { 
return (
<Calendar 
date={this.state.date} 
onPrevButtonPress={() => this.handlePrevButtonPress()} 
onNextButtonPress={() => this.handleNextButtonPress()} 
onDateSelect={(date) => this.handleDateSelect(date)} /> 
); 
} 
} 
+0

** **解決:https://github.com/nikches/react-native-calendar/issues/2 – Akki

回答

1

您正在錯誤地導入日曆組件。

試試這個:

import Calendar from 'react-native-calendar-component';

+0

我想這一個,但它給同錯誤。我也嘗試從github鏈接複製index.js文件,將其重命名爲Calendar.js並將其作爲'。Calendar/js''的導入日曆導入。試過這個'從'./node_modules/react-native-calendar-component'導入日曆;' – Akki

+0

你看到了什麼錯誤? –

+0

null不是一個對象(評估this.state.date) – Akki

相關問題