Created
August 30, 2019 07:52
-
-
Save Spyna/0741bf0f0ed180e344f09939f3ba5c6c to your computer and use it in GitHub Desktop.
A React Component that uses the usePushNotificationHook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import usePushNotifications from "./usePushNotifications"; | |
export default function PushNotificationDemo() { | |
const { | |
userConsent, | |
pushNotificationSupported, | |
userSubscription, | |
onClickAskUserPermission, | |
onClickSusbribeToPushNotification, | |
onClickSendSubscriptionToPushServer, | |
pushServerSubscriptionId, | |
onClickSendNotification, | |
error, | |
loading | |
} = usePushNotifications(); | |
return ( | |
<div> | |
{error && ( | |
<section className="app-error"> | |
<h2>{error.name}</h2> | |
<p>Error message : {error.message}</p> | |
<p>Error code : {error.code}</p> | |
</section> | |
)} | |
{loading && "Loading, please stand by"} | |
<p>Push notification are {!pushNotificationSupported && "NOT"} supported by your device.</p> | |
<p> | |
User consent to recevie push notificaitons is <strong>{userConsent}</strong>. | |
</p> | |
<button onClick={onClickAskUserPermission}>Ask user permission</button> | |
<button onClick={onClickSusbribeToPushNotification}>Create Notification subscription</button> | |
<button onClick={onClickSendSubscriptionToPushServer}>Send subscription to push server</button> | |
<button onClick={onClickSendNotification}>Send a notification</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment