我正在尝试此组件reation-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)} />
);
}
}
您错误地导入日历组件。
而是尝试一下:
import Calendar from 'react-native-calendar-component';