反应 js blueprintjs 日期范围选择器不起作用
react js blueprintjs Date Range Picker not work
我需要在 BlueprintJS(documentation) 上创建 DateRangePicker,并在我的组件中创建 RangePicker,
就像这个 screenshot.
我安装了所有 npm 包,并按照说明进行操作:
import { DateRangePicker } from "@blueprintjs/datetime";
<DateRangePicker
value={[this.state.startDate, this.state.endDate]}
onChange={this.handleDateChange}
/>
但无论如何都有错误:
Cannot read property 'startDate' of null
TypeError: Cannot read property 'startDate' of null
请帮忙,我需要什么来工作 DateRangePicker
您应该将 state
定义为组件的字段。默认情况下,如果不设置state
,则等于null
import React from 'react'
import { DateRangePicker } from "@blueprintjs/datetime";
class MyAwesomeComponent extends React.Component {
constructor(props) {
super(props)
this.state = {
startDate: new Date("2018-05-01T12:13:30.643Z"),
endDate: new Date("2018-05-03T12:13:30.643Z")
}
}
render() {
return (
<div className="my-component">
<DateRangePicker
value={[this.state.startDate, this.state.endDate]}
onChange={this.handleDateChange}
/>
</div>
)
}
}
我需要在 BlueprintJS(documentation) 上创建 DateRangePicker,并在我的组件中创建 RangePicker, 就像这个 screenshot.
我安装了所有 npm 包,并按照说明进行操作:
import { DateRangePicker } from "@blueprintjs/datetime";
<DateRangePicker
value={[this.state.startDate, this.state.endDate]}
onChange={this.handleDateChange}
/>
但无论如何都有错误:
Cannot read property 'startDate' of null
TypeError: Cannot read property 'startDate' of null
请帮忙,我需要什么来工作 DateRangePicker
您应该将 state
定义为组件的字段。默认情况下,如果不设置state
,则等于null
import React from 'react'
import { DateRangePicker } from "@blueprintjs/datetime";
class MyAwesomeComponent extends React.Component {
constructor(props) {
super(props)
this.state = {
startDate: new Date("2018-05-01T12:13:30.643Z"),
endDate: new Date("2018-05-03T12:13:30.643Z")
}
}
render() {
return (
<div className="my-component">
<DateRangePicker
value={[this.state.startDate, this.state.endDate]}
onChange={this.handleDateChange}
/>
</div>
)
}
}