Socket
Socket
Sign inDemoInstall

@dotmind/react-use-pwa

Package Overview
Dependencies
0
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dotmind/react-use-pwa

Prompt to install Progressive Web App and more with React hooks


Version published
Weekly downloads
687
decreased by-0.43%
Maintainers
3
Created
Weekly downloads
 

Readme

Source
header

@dotmind/react-use-pwa

Prompt to install Progressive Web App and more with React hooks. Builded by .mind.io

Menu

✋ Disclaimer

This package help to prompt to install and manage Progressive Web App (PWA) installed with React hooks.

Please check if your app have the required criteria before use : web.dev/install-criteria

Want to make a good PWA ? Read this

SSR support ✅

💻 Installation

yarn add @dotmind/react-use-pwa

or

npm i @dotmind/react-use-pwa --save

👷‍♂️ How it's work

usePwa usage

import { useEffect, useCallback  } from 'react';
import { usePwa } from '@dotmind/react-use-pwa';

const App = () => {
  const {
    installPrompt,
    isInstalled,
    isStandalone,
    isOffline,
    canInstall,
  } = usePwa();

  const handleInstallPrompt = useCallback(() => {
    if (canInstall) {
      installPrompt();
    }
  }, [canInstall, installPrompt]);

  if (isOffline) {
    return <p>Please check your network 📶</p>;
  }

  if (!isInstalled || !isStandalone) {
    return (
      <button onClick={handleInstallPrompt}>
        <span>Hey install our app 👋</span>
      </button>
    );
  }

  return (
    <h1>Welcome to our new app 🚀</h1>
  );
};

descriptiontype
installPromptShow install prompt() => Promise<void>
isInstalledIs app installed on deviceboolean
isStandaloneIs app run in standalone modeboolean
isOfflineIs app run in offline modeboolean
canInstallDevice can install appboolean
userChoicePrompt user choice'accepted' | 'dismissed' | 'unknow'

usePwaAppSize usage

Choose app launching width and height (only in desktop standalone mode).

import { usePwaAppSize } from '@dotmind/react-use-pwa';

const App = () => {
  usePwaAppSize(400, 560);

  return <AppProvider />;
};
argumentsdescriptionrequireddefault value
widthApp widthfalse800
heightApp heightfalse800
optionsApp optionsfalse{ fixed: false }

App options

optiondescriptiontype
fixedUser can't resize app width & heightboolean

⚡️ Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

🔐 License

MIT

Keywords

FAQs

Last updated on 23 Apr 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc