New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-pwa-push-notifications

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-pwa-push-notifications

React hook for push notifications

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React hook Push Notifications

Overview

This package provides a custom React hook for facilitating push subscriptions in your application. It ensures proper handling of browser APIs and returns easy-to-handle errors in case of issues.

Installation

npm install react-pwa-push-notifications

or

yarn add react-pwa-push-notifications

Usage

First, import the hook:

import { useSubscribe, Errors } from 'react-pwa-push-notifications';

Then, initialize it with your public VAPID key:

const { getSubscription } = useSubscribe({ publicKey: 'YOUR_PUBLIC_KEY_HERE' });

Use getSubscription to initiate the push subscription:

const subscribeUser = async () => {
  try {
    const subscription = await getSubscription();
    // Handle the new subscription object
  } catch (error) {
    if (error.errorCode === Errors.ServiceWorkerAndPushManagerNotSupported) {
      // Handle service worker or push manager not being supported
    } else if (error.errorCode === Errors.PushManagerUnavailable) {
      // Handle PushManager unavailable
    } else if (error.errorCode === Errors.ExistingSubscription) {
      // Handle existing subscription
    } else {
      // Handle other errors
    }
  }
};

Error Handling

The hook provides an Errors enum for better error management. It includes the following error codes:

  • ServiceWorkerAndPushManagerNotSupported: The service worker or push manager is not supported by the browser.
  • PushManagerUnavailable: The PushManager is unavailable.
  • ExistingSubscription: An existing subscription is already present.
  • Unknown: An unknown error has occurred.

Contributing

Feel free to open issues or pull requests if you want to improve this package.

License

MIT


This README provides an example usage and can be expanded based on additional features or requirements.

Keywords

FAQs

Package last updated on 22 Sep 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