Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-date-range

Package Overview
Dependencies
Maintainers
4
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-date-range

A React component for choosing dates and date ranges.

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
288K
increased by7.17%
Maintainers
4
Weekly downloads
 
Created

What is react-date-range?

The react-date-range package is a flexible and customizable date picker component for React applications. It allows users to select single dates, date ranges, and even predefined ranges with ease. The package is highly configurable and supports various themes and locales.

What are react-date-range's main functionalities?

Single Date Picker

This feature allows users to select a single date. The component is configured to show a single month and allows the user to pick a date within that month.

import { DateRangePicker } from 'react-date-range';

const SingleDatePicker = () => {
  const [state, setState] = useState({
    startDate: new Date(),
    endDate: new Date(),
    key: 'selection'
  });

  return (
    <DateRangePicker
      ranges={[state]}
      onChange={item => setState(item.selection)}
      showSelectionPreview={true}
      moveRangeOnFirstSelection={false}
      months={1}
      direction="horizontal"
    />
  );
};

Date Range Picker

This feature allows users to select a range of dates. The component provides a user-friendly interface to pick start and end dates.

import { DateRangePicker } from 'react-date-range';

const DateRangeSelector = () => {
  const [state, setState] = useState({
    selection: {
      startDate: new Date(),
      endDate: new Date(),
      key: 'selection'
    }
  });

  return (
    <DateRangePicker
      ranges={[state.selection]}
      onChange={item => setState({ selection: item.selection })}
    />
  );
};

Predefined Ranges

This feature allows users to select from predefined date ranges such as 'Today' or 'Last 7 Days'. It simplifies the process of selecting common date ranges.

import { DateRangePicker } from 'react-date-range';

const PredefinedRanges = () => {
  const [state, setState] = useState({
    selection: {
      startDate: new Date(),
      endDate: new Date(),
      key: 'selection'
    }
  });

  const predefinedRanges = [
    {
      label: 'Today',
      range: () => ({ startDate: new Date(), endDate: new Date() })
    },
    {
      label: 'Last 7 Days',
      range: () => ({ startDate: new Date(new Date().setDate(new Date().getDate() - 7)), endDate: new Date() })
    }
  ];

  return (
    <DateRangePicker
      ranges={[state.selection]}
      onChange={item => setState({ selection: item.selection })}
      staticRanges={predefinedRanges}
    />
  );
};

Other packages similar to react-date-range

Keywords

FAQs

Package last updated on 22 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc