简体   繁体   English

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

[英]react js blueprintjs Date Range Picker not work

I need create DateRangePicker on BlueprintJS( documentation ) and RangePicker in my component, like in this screenshot . 我需要在BlueprintJS( documentation )和RangePicker上的组件中创建DateRangePicker,如此屏幕截图所示

I instalation all npm packages, and do all by instructions: 我安装了所有npm软件包,并按照说明进行操作:

import { DateRangePicker } from "@blueprintjs/datetime";

<DateRangePicker
    value={[this.state.startDate, this.state.endDate]}
    onChange={this.handleDateChange}
/>

but anyway have error: 但仍然有错误:

Cannot read property 'startDate' of null
TypeError: Cannot read property 'startDate' of null

please, help, what i need for working DateRangePicker 请帮忙,我需要什么来工作DateRangePicker

You should define state as field of your component. 您应该将state定义为组件的字段。 By default, if state is not set, it equals to null 默认情况下,如果未设置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