Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@medipass/react-service-worker

Package Overview
Dependencies
Maintainers
8
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@medipass/react-service-worker

A headless React component that wraps around the Navigator Service Worker API.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
8
Weekly downloads
 
Created
Source

React Service Worker

A headless React component that wraps around the Navigator Service Worker API.

Table of Contents

Installation

npm install @medipass/react-service-worker --save

or install with Yarn if you prefer:

yarn add @medipass/react-service-worker

Usage

Basic

Import the <WithServiceWorker> component and wrap it around your application.

import React from 'react';
import WithServiceWorker from 'react-service-worker';

import App from './App';

export default () => (
  <WithServiceWorker publicServiceWorkerDest="/service-worker.js">
    <App />
  </WithServiceWorker>
);

Less basic

import React from 'react';
import WithServiceWorker from 'react-service-worker';

import App from './App';

export default () => (
  <WithServiceWorker
    onError={err => console.log(`An error occured: ${err}`)}
    onInstalled={err => console.log('Service worker installed')}
    onUpdated={err => console.log('Service worker updated')}
    publicServiceWorkerDest="/service-worker.js"
  >
    {({ registration, update, unregister }) => (
      <div>
        <App />
        <button onClick={update}>Update service worker</button>
        <button onClick={unregister}>Unregister service worker</button>
      </div>
    )}
  </WithServiceWorker>
);

<WithServiceWorker> props

publicServiceWorkerDest

string

The destination of where your service worker is located.

Example usage:

<WithServiceWorker publicServiceWorkerDest="/service-worker.js">

publicUrl

string | Optional

The public URL of your application. Defaults to the root origin.

Example usage:

<WithServiceWorker publicUrl="https://example.com/app">

onError

function(error: Error) | Optional

Invoked when an error occurs during service worker registration.

Example usage:

<WithServiceWorker onError={err => console.log(`An error occured! Error: ${err}`)}>

onInstalled

function() | Optional

Invoked when the service worker is installed.

Example usage:

<WithServiceWorker onInstalled={err => console.log('Service worker successfully installed.')}>

onUpdated

function() | Optional

Invoked when the service worker is updated.

Example usage:

<WithServiceWorker onUpdated={err => console.log('Service worker successfully updated.')}>

registerOnMount

boolean | Optional | Default: true

Invoked when the service worker is updated.

Example usage:

<WithServiceWorker registerOnMount={process.env.PRODUCTION}>

children Render Props

registration

Object

The instance of the registered service worker.

register

function()

When invoked, register will register the service worker.

update

function()

When invoked, update will update the service worker.

unregister

function()

When invoked, unregister will unregister the service worker.

License

MIT © Medipass Solutions Pty. Ltd.

Keywords

FAQs

Package last updated on 07 Aug 2018

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