Reputation: 1251
I am trying this component react-native-calendar
It always gives error null is not an object (evaluating this.state.date)
I tried initializing state variable named state and assign it date value but error still exists.
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)} />
);
}
}
Upvotes: 0
Views: 1876
Reputation: 6689
You are importing the calendar component wrongly.
Try this instead:
import Calendar from 'react-native-calendar-component';
Upvotes: 1