简体   繁体   中英

react js blueprintjs Date Range Picker not work

I need create DateRangePicker on BlueprintJS( documentation ) and RangePicker in my component, like in this screenshot .

I instalation all npm packages, and do all by instructions:

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

You should define state as field of your component. By default, if state is not set, it equals to 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>
        )
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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