@platformbuilders/use-notifications
v0.1.9
Published
[![Build Status][check-badge]][workflows] [![codecov][codecov]](https://codecov.io/gh/platformbuilders/use-notifications) [![npm][npm-badge]][npm] [![MIT][license-badge]][license]
Downloads
12
Readme
@platformbuilders/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 @platformbuilders/use-notifications
then, navigate to cd ios
and run pod install
Usage to configure
import { useNotifications } from '@platformbuilders/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 '@platformbuilders/use-notifications';
const { displayNotification } = useNotifications();
useEffect(() => {
displayNotification({
title: 'Bem vindo ao App',
body: 'Faça login para continuar',
});
}, []);
New Version
To test locally see: Testando NPM packages localmente
To publish a new version see: Testando NPM packages localmente