hypeserver / react-date-range

A React component for choosing dates and date ranges.
MIT License
2.57k stars 658 forks source link

utils.js:69 Uncaught TypeError: Cannot read properties of undefined (reading 'findIndex') #575

Open forgowhisky opened 2 years ago

forgowhisky commented 2 years ago

Subject of the issue

When trying to render the component, the following error occurs:

utils.js:69 Uncaught TypeError: Cannot read properties of undefined (reading 'findIndex')

[BUG] Bug Reproduce Steps

Simply install the package on any react app, import it, and render it with

[BUG] Expected behaviour

the app to not crash and the date range picker to display

Environment

Package Version: 1.4.0 React version: 17.0.2 Node version: any Browser: chrome

StanlyLife commented 1 year ago

You get this error when ranges is malformed, in my case my object was:

{
    "startDate": "2022-06-01T00:00:00.000Z",
    "endDate": "2022-06-29T00:00:00.000Z",
    "key": "selection"
}

when ranges should be

[
    {
        "startDate": "2022-06-01T00:00:00.000Z",
        "endDate": "2022-06-29T00:00:00.000Z",
        "key": "selection"
    }
]

it should be of type array, not object

aminebya1 commented 1 year ago

Hey, if you using class componenet you should pass the value onChange like this : this.setState({range:[range.selection]})