繁体   English   中英

反应js blueprintjs日期范围选择器不起作用

[英]react js blueprintjs Date Range Picker not work

我需要在BlueprintJS( documentation )和RangePicker上的组件中创建DateRangePicker,如此屏幕截图所示

我安装了所有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>
        )
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM