0.3.3 • Published 2 years ago

@atiladev/usecalendar v0.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

useCalendar Hook 🚀

made with expo

Updated to Expo SDK46

Blog post

To learn more about using this hook and see it in action, read the post!

What is it for

This is an easy hook to use expo-calendar. It allows you:

  • Get access permission to calendar
  • Open settings to give access permission to calendar
  • Create a new calendar and store it on your device
  • Add events to the calendar
  • Get all events
  • Get calendarId
  • Check if an event exists inside of the calendar created
  • Delete the calendar and all events inside of it

Install

npm install @atiladev/usecalendar

or

yarn add @atiladev/usecalendar

After installing the hook, you'll have to install the following libraries

$ npx expo install expo-calendar expo-localization @react-native-async-storage/async-storage

How to use it

Start by importing the useCalendar hook and then import the packages that you need to interact with the Calendar:

import useCalendar from '@atiladev/usecalendar';

const {
  addEventsToCalendar,
  createCalendar,
  deleteCalendar,
  getCalendarId,
  getEvents,
  getPermission,
  isThereEvents,
  openSettings,
} = useCalendar('App_Name', '#BADA55', 'Calendar_Name');

const createCalAndEvent = async () => {
  const granted = await getPermission();

  if (granted) {
    await createCalendar();
    let eventExists = await isThereEvents();

    if (!eventExists) {
      try {
        addEventsToCalendar('Event title', new Date(), new Date());
      } catch (e) {
        // Something went wrong
      }
    }
  } else {
    openSettings();
  }
};

const removeCalendar = () => deleteCalendar();

useCalendar

useCalendar(title: string, color: string, storeName: string);

useCalendar returns:

getPermission: () => Promise<Calendar[] | undefined>

createCalendar: () => Promise<void>

addEventsToCalendar: (eventTitle: string, eventStartDate: Date, eventEndDate: Date) => Promise<void>

deleteCalendar: () => Promise<void>

openSettings: () => Promise<void>

isThereEvents: () => Promise<boolean>

getEvents: () => Promise<Calendar.Event[]>

getCalendarId: () => Promise<any>

⭐️ If this hook is useful for you, please consider giving it a star. This motivates us to continue working on this and adding new features. Thanks!

Developed with ❤️ by Leandro Favre (AtilaDev)

0.3.0

2 years ago

0.2.0

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.9

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.3

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago