Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant import static ranges #196

Closed
suhailsulu opened this issue Apr 27, 2018 · 5 comments
Closed

Cant import static ranges #196

suhailsulu opened this issue Apr 27, 2018 · 5 comments

Comments

@suhailsulu
Copy link

When I try to import staticRanges
import { staticRanges} from 'react-date-range',

I am getting undefined, so I couldn't create my own static ranges

@mkg0
Copy link
Collaborator

mkg0 commented Apr 27, 2018

You should create predefined ranges with createStaticRanges function. You can dissect here for usage: https://github.com/Adphorus/react-date-range/blob/master/src/defaultRanges.js#L51.

const predefinedRanges = createStaticRanges([
  {
    label: 'Today',
    range() {
      return {
        startDate: defineds.startOfToday,
        endDate: defineds.endOfToday,
      };
    },
  }
]);

But you shouldn't get undefined when importing staticRanges. You have installed it with next tag, right?

@suhailsulu
Copy link
Author

Yes, I installed using next tag.
I couldn't see any staticRanges export in https://github.com/Adphorus/react-date-range/blob/master/src/defaultRanges.js,
Is that a problem??

mkg0 added a commit that referenced this issue Apr 27, 2018
@mkg0
Copy link
Collaborator

mkg0 commented Apr 27, 2018

@suhailsulu you're right. It should be defaultStaticRanges and I fixed exports too. It will be fixed after next release.
Still, you can create custom defined ranges like above comment. You can reopen if have any trouble again about it.

@mkg0 mkg0 closed this as completed Apr 27, 2018
@dsternlicht
Copy link

Just FYI, if you want to extend the default static ranges, here's a working code sample:

import { DateRangePicker, defaultStaticRanges, createStaticRanges } from 'react-date-range';

const staticRanges = [
  ...defaultStaticRanges,
  ...createStaticRanges([
    {
      label: 'Begining of Time',
      range: () => ({
        startDate: START_DATE,
        endDate: new Date()
      })
    }
  ])
];

arthot pushed a commit to arthot/react-date-range that referenced this issue Oct 27, 2018
@Sailokeshg
Copy link

Sailokeshg commented Jun 22, 2022

Recently it is not accepting the above structure
{
label: 'Begining of Time',
range: () => ({
startDate: START_DATE,
endDate: new Date()
})
}
It is expecting to have isSelected in this structure as
{
label: 'Begining of Time',
range: () => ({
startDate: START_DATE,
endDate: new Date()
})
isSelected : (range: Range) => boolean
}

Can someone help me how to use this. When i place this the selected range is not getting highlited

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants