@buildersbank/use-notifications
TypeScript icon, indicating that this package has built-in type declarations

0.1.7 • Public • Published

Build Status codecov npm MIT

@buildersbank/use-notification

Wrapping up @react-native-firebase/messaging and @notifee/react-native as a hook for simpler usage.

Install

yarn add @react-native-firebase/messaging @react-native-firebase/app @notifee/react-native @buildersbank/use-notifications

then, navigate to cd ios and run pod install

Usage to configure

import { useNotifications } from '@buildersbank/use-notifications';

const { configureNotifications, getFCMToken } = useNotifications();

const onRegisterNotification = async (token) => {
  console.log('LOG: onRegisterNotification -> token', token);
};

const onReceiveNotification = (notification) => {
  console.log('LOG: onNotification -> notification', notification);
};

const onOpenNotification = (notification) => {
  console.log('LOG: onOpenNotification -> notification', notification);
};

const onTokenRefresh = (token) => {
  console.log('LOG: onTokenRefresh -> token', token);
};

const getFirebaseToken = async () => {
  const fcmToken = await getFCMToken();
  console.log('LOG: getFirebaseToken -> fcmToken', fcmToken);
};

useEffect(() => {
  configureNotifications({
    onRegister: onRegisterNotification,
    onNotification: onReceiveNotification,
    onNotificationOpened: onOpenNotification, // iOS
    onTokenRefresh: onTokenRefresh
  });
}, []);

Usage to display notifications

import { useNotifications } from '@buildersbank/use-notifications';

const { displayNotification } = useNotifications();

useEffect(() => {
  displayNotification({
    title: 'Bem vindo ao App',
    body: 'Faça login para continuar',
  });
}, []);

New Version

Readme

Keywords

none

Package Sidebar

Install

npm i @buildersbank/use-notifications

Weekly Downloads

0

Version

0.1.7

License

MIT

Unpacked Size

72.7 kB

Total Files

34

Last publish

Collaborators

  • buildersbank