Socket
Socket
Sign inDemoInstall

@react-native-community/datetimepicker

Package Overview
Dependencies
Maintainers
30
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-native-community/datetimepicker

DateTimePicker component for React Native


Version published
Maintainers
30
Created

What is @react-native-community/datetimepicker?

@react-native-community/datetimepicker is a React Native module that provides a cross-platform Date and Time Picker component. It allows developers to easily integrate date and time selection functionality into their React Native applications, supporting both iOS and Android platforms.

What are @react-native-community/datetimepicker's main functionalities?

Date Picker

This feature allows users to select a date from a calendar interface. The code sample demonstrates how to display a date picker when a button is pressed and update the state with the selected date.

import DateTimePicker from '@react-native-community/datetimepicker';

const App = () => {
  const [date, setDate] = useState(new Date());
  const [show, setShow] = useState(false);

  const onChange = (event, selectedDate) => {
    const currentDate = selectedDate || date;
    setShow(false);
    setDate(currentDate);
  };

  return (
    <View>
      <Button onPress={() => setShow(true)} title="Show Date Picker" />
      {show && (
        <DateTimePicker
          value={date}
          mode="date"
          display="default"
          onChange={onChange}
        />
      )}
    </View>
  );
};

Time Picker

This feature allows users to select a time from a clock interface. The code sample demonstrates how to display a time picker when a button is pressed and update the state with the selected time.

import DateTimePicker from '@react-native-community/datetimepicker';

const App = () => {
  const [time, setTime] = useState(new Date());
  const [show, setShow] = useState(false);

  const onChange = (event, selectedTime) => {
    const currentTime = selectedTime || time;
    setShow(false);
    setTime(currentTime);
  };

  return (
    <View>
      <Button onPress={() => setShow(true)} title="Show Time Picker" />
      {show && (
        <DateTimePicker
          value={time}
          mode="time"
          display="default"
          onChange={onChange}
        />
      )}
    </View>
  );
};

Date and Time Picker

This feature allows users to select both date and time from a combined interface. The code sample demonstrates how to display a date and time picker when a button is pressed and update the state with the selected date and time.

import DateTimePicker from '@react-native-community/datetimepicker';

const App = () => {
  const [dateTime, setDateTime] = useState(new Date());
  const [show, setShow] = useState(false);

  const onChange = (event, selectedDateTime) => {
    const currentDateTime = selectedDateTime || dateTime;
    setShow(false);
    setDateTime(currentDateTime);
  };

  return (
    <View>
      <Button onPress={() => setShow(true)} title="Show DateTime Picker" />
      {show && (
        <DateTimePicker
          value={dateTime}
          mode="datetime"
          display="default"
          onChange={onChange}
        />
      )}
    </View>
  );
};

Other packages similar to @react-native-community/datetimepicker

Keywords

FAQs

Package last updated on 11 Oct 2023

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